This topic is locked
[SOLVED]

 Show a field in the add /inline add based on a value of another

11/28/2013 5:05:20 PM
PHPRunner General questions
I
ianhols author

I have a database all set up (PHP runner). However I am trying to do the following:-
If a certain value is selected from a pull down list in one field , then another field is enabled (disabled by default)
hope you can help
thanks
Ian

C
copper21 11/28/2013

You can do this in the Javascript Onload event.
It would look something like this: Make sure to make the field writeable in the "edit as" tab if you double click on the field on the page; don't make it readonly.
Javascript Onload event in the events section of the page you want to do this with.
//Create Variables and Get Values
var DropDown = Runner.getControl(pageid, 'DropDownFieldName');

var DisableField = Runner.getControl(pageid, 'FieldToBeDisabled');
//Disable Field to Start
DisableField.setDisabled();

DisableField.removeValidation("IsRequired");
//Enable Field if "SOMETHING" is chosen from drop down box
DropDown.on('change', function (e){

if(this.getValue() == 'SOMETHING'){
DisableField.setEnabled();

DisableField.addValidation("IsRequired");
}});
//Disable field if something other than "Something" is chosen from the drop down field
DropDown.on('change', function (e){

if(this.getValue() != 'SOMETHING'){
DisableField.setDisabled();

DisableField.removeValidation("IsRequired");
}});
This will automatically disable the field you want disabled and if "Something" is chosen from the drop down menu, it will enable the field. It will also add a validation to make it a required field if it is enabled. Remember to replace "DropDownFieldName" and "FieldToBeDisabled" with the name of your fields in the form.
Brian

I
ianhols author 12/1/2013



You can do this in the Javascript Onload event.
It would look something like this: Make sure to make the field writeable in the "edit as" tab if you double click on the field on the page; don't make it readonly.
Javascript Onload event in the events section of the page you want to do this with.
//Create Variables and Get Values
var DropDown = Runner.getControl(pageid, 'DropDownFieldName');

var DisableField = Runner.getControl(pageid, 'FieldToBeDisabled');
//Disable Field to Start
DisableField.setDisabled();

DisableField.removeValidation("IsRequired");
//Enable Field if "SOMETHING" is chosen from drop down box
DropDown.on('change', function (e){

if(this.getValue() == 'SOMETHING'){
DisableField.setEnabled();

DisableField.addValidation("IsRequired");
}});
//Disable field if something other than "Something" is chosen from the drop down field
DropDown.on('change', function (e){

if(this.getValue() != 'SOMETHING'){
DisableField.setDisabled();

DisableField.removeValidation("IsRequired");
}});
This will automatically disable the field you want disabled and if "Something" is chosen from the drop down menu, it will enable the field. It will also add a validation to make it a required field if it is enabled. Remember to replace "DropDownFieldName" and "FieldToBeDisabled" with the name of your fields in the form.
Brian


Thanks Brian ...
But I am struggling to get this to work
If I place the code in the upload javascript function , nothing this seems to work. So i thought i would use part of the code....just using the function to disable a field....still not working
The lookup field is called "From" (this is based on the field name in the table), this also contains a default value

The field to be enabled is called "Number" ..... (this is based on the field name in the table)
So the "From" field contains a list .....if the list as the name "Internal" selected it should display the "Number" field , where the user can enter an internal reference number .... If the "From" contains anything else , then the "Number" field , should disappear from the "add" page/form.
Many thanks

Ian

Sergey Kornilov admin 12/1/2013