This topic is locked
[SOLVED]

 Disabling a field based on a value in same table

7/22/2011 12:13:54 PM
PHPRunner General questions
P
pim author

I think i have a very simple question.
I have a table called 'd_pics'. In this table are 3 fields:
PicID [int] [PRIMARY KEY]

Pictype [varchar][LOOK UP from LIST OF VALUES: value 1= Card, value 2= Online]

SerialNr [varchar] {see question]
Now if in the form the value 'Online' is selected, the field 'SerialNr' should be disabled.

But if in the form the value 'Card' is selected, the user should fill out a value at the field 'SerialNr'.
I've tried the code below as I found in http://www.asprunner...drop-down-box/. But it doesn't work and is also based on the fact that the second field (in my case SerialNr) would be a dropdown. In my case the user should fill out something by him selves.
var tName = 'd_pics';

var ctrlPicType = Runner.controls.ControlManager.getAt(tName, pageid, 'PicType');

var ctrlSerialNr = Runner.controls.ControlManager.getAt(tName, pageid, 'SerialNr');
ctrlCountry.on('change', function(e){

if (this.getValue() == 'Card'){

ctrlState.setEnabled();

ctrlState.addValidation("IsRequired");

}else{

ctrlState.setDisabled();

ctrlState.setValue("");

ctrlState.removeValidation("IsRequired");

}

});

C
cgphp 7/22/2011

You have to change the code to adapt it to your case. This should work



var ctrlPicType = Runner.getControl(pageid, 'PicType');

var ctrlSerialNr = Runner.getControl(pageid, 'SerialNr');
ctrlPicType.on('change', function(e){

if (this.getValue() == 'Card'){

ctrlSerialNr.setEnabled();

ctrlSerialNr.addValidation("IsRequired");

}else{

ctrlSerialNr.setDisabled();

ctrlSerialNr.setValue("");

ctrlSerialNr.removeValidation("IsRequired");

}

});
P
pim author 7/22/2011

Wow, thank you for the very quick answer! And your code worked!
You are superman! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=59609&image=1&table=forumreplies' class='bbc_emoticon' alt=':P' />

P
pim author 7/22/2011

And now I also understand what I did completely wrong before. Really thank you!
If you'd still could help me out with my other question, that would be really great:

http://www.asprunner.com/forums/topic/17416-limiting-the-child-rows/