This topic is locked
[SOLVED]

 Disable fields based on other field

9/25/2018 2:37:07 PM
ASPRunner.NET General questions
I
i.NoLim author

I have 4 text fields "A," "B, "C, and "D." All fields should be enabled when opening a new form, once a value has been entered for one of the fields the other 3 should be disabled. If the value is then deleted, meaning the field is now blank, all 4 fields should be enabled.
I've tried the following but it doesn't work, unsure if ctrl.on(change, function (e) ) only works on dropdowns and checkboxes.

var ctrlA = Runner.getControl(pageid, 'A');

var ctrlB = Runner.getControl(pageid, 'B');

var ctrlC = Runner.getControl(pageid, 'C');

var ctrlD = Runner.getControl(pageid, 'D');
ctrlA.on('change', function(e)

{

if(this.getValue() != '')

{

ctrlB.setDisabled();

ctrlC.setDisabled();

ctrlD.setDisabled();

}

else

{

ctrlB.setEnabled();

ctrlC.setEnabled();

ctrlD.setEnabled();

}

}

ctrlB.on('change', function(e)

{

if(this.getValue() != '')

{

ctrlA.setDisabled();

ctrlC.setDisabled();

ctrlD.setDisabled();

}

else

{

ctrlA.setEnabled();

ctrlC.setEnabled();

ctrlD.setEnabled();

}

}

ctrlC.on('change', function(e)

{

if(this.getValue() != '')

{

ctrlA.setDisabled();

ctrlB.setDisabled();

ctrlD.setDisabled();

}

else

{

ctrlA.setEnabled();

ctrlB.setEnabled();

ctrlD.setEnabled();

}

}

ctrlD.on('change', function(e)

{

if(this.getValue() != '')

{

ctrlA.setDisabled();

ctrlB.setDisabled();

ctrlC.setDisabled();

}

else

{

ctrlA.setEnabled();

ctrlB.setEnabled();

ctrlC.setEnabled();

}

}
A
Arkie 9/28/2018

I had a problem with using disable() and enable() too. We should ask support for a little assistance on this.
However, in my case, I was able to accomplish my goal by using hide() and show() instead. The only problem I had was I might lose focus with some orders of entry.
BTW.. you my need to consider having a reset() since once data is entered, it completes this routine.

admin 10/2/2018

It looks like you guys are trying to guess what might be wrong instead of solving the issue.
You need to open this page in web browser, open Developers Tools, find this code in events Javascript file, set a break point somewhere in the begging of "onchange" event, trigger that event and step through the code seeing what exactly is happening and why your code doesn't work.
You just cannot guess it. Need to look into the source of the issue.

jadachDevClub member 10/2/2018

Sergey is right. However, you may want to try combining all this and use else if.

I
i.NoLim author 10/2/2018

Thank you all for your replies.
I've never used .setDisabled or .setEnabled before so I decided to test things out using hide() and show() as Arkie recommend it. Only 'A' would show, the rest were hidden. I kept going back and forth looking for errors but found none. After a while I decided to delete everything in the JavaScrip OnLoad Event and rewrite it exactly the same. Everything works now, I'm not sure what was wrong.
Thank you again.

A
Arkie 10/2/2018



Thank you all for your replies.
I've never used .setDisabled or .setEnabled before so I decided to test things out using hide() and show() as Arkie recommend it. Only 'A' would show, the rest were hidden. I kept going back and forth looking for errors but found none. After a while I decided to delete everything in the JavaScrip OnLoad Event and rewrite it exactly the same. Everything works now, I'm not sure what was wrong.
Thank you again.


Are you saying you did get this to work using .setDisabled and .setEnabled ??
I have a small app where they don't work, so maybe I should rewrite it and maybe look for an error as the admin suggested. Show and hide worked for me, so I never looked back... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=86063&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

I
i.NoLim author 10/2/2018



Are you saying you did get this to work using .setDisabled and .setEnabled ??
I have a small app where they don't work, so maybe I should rewrite it and maybe look for an error as the admin suggested. Show and hide worked for me, so I never looked back... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=86065&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />



I didn't check .setDisabled or .setEnabled as hide() and show() work for what I'm looking for. I'll give it a shot and post updates.