I have an item X which can take two values on or off. depending on the value , i want items y and z to be activated/deactivated.When x is on y is not filled in, hence any validation on the fields in item y should be skipped. the same applies when x is off for z. Hence when x is on, i am setting the item y as valid always so that the fields of item y need not be filled and the same applies for z when x is off. The code used is given belowIWEventRegistry.addItemHandler("/cont/x", "onItemChange", SelectObject); function SelectObject() { var typeItem=IWDatacapture.getItem("/cont/x"); var flag = typeItem.getOptions()[typeItem.getValue()].value == "on"; if(flag){ IWDatacapture.getItem("/cont/y").setValid(true); }else{ IWDatacapture.getItem("/cont/z").setValid(true); } }This is not working, irrespective of whether x is on or off, save is not possible without fulfilling all the validation on fields of y and z. any suggestions?thanks
The statement(assignment and comparison) works fine. i tried to make the y/z items invisible depending on value of x within the function and that worked. However, Is the usage of setvalid appropriate and correct here? Is there any alternative to completely remove the y/z item depending on value of x?
I have an item X which can take two values on or off. depending on the value , i want items y and z to be activated/deactivated.When x is on y is not filled in, hence any validation on the fields in item y should be skipped. the same applies when x is off for z. Hence when x is on, i am setting the item y as valid always so that the fields of item y need not be filled and the same applies for z when x is off. The code used is given belowIWEventRegistry.addItemHandler("/cont/x", "onItemChange", SelectObject); function SelectObject() { var typeItem=IWDatacapture.getItem("/cont/x"); var flag = typeItem.getOptions()[typeItem.getValue()].value == "on"; if(flag) { IWDatacapture.getItem("/cont/y").setValid(true); } else { IWDatacapture.getItem("/cont/z").setValid(true); } }This is not working, irrespective of whether x is on or off, save is not possible without fulfilling all the validation on fields of y and z. any suggestions?thanks
function SelectObject(item) { var flag = (item.getOptions()[item.getValue()].value == "on"); if(flag) { // x is on IWDatacapture.getItem("/cont/y").setValid(true); IWDatacapture.getItem("/cont/y").setRequired(false); IWDatacapture.getItem("/cont/y").setVisible(false); IWDatacapture.getItem("/cont/z").setRequired(true); IWDatacapture.getItem("/cont/z").setVisible(true); } else { // x is off IWDatacapture.getItem("/cont/z").setValid(true); IWDatacapture.getItem("/cont/z").setRequired(false); IWDatacapture.getItem("/cont/z").setVisible(false); IWDatacapture.getItem("/cont/y").setRequired(true); IWDatacapture.getItem("/cont/y").setVisible(true); } }
function SelectObject(item) { var flag = (item.getOptions()[item.getValue()].value == "on"); var y_item = IWDatacapture.getItem("/cont/y"); var z_item = IWDatacapture.getItem("/cont/z"); if(flag) { // x is ondisable(y_item); enable(z_item); } else { // x is off disable(z_item); enable(y_item); }}function disable(item){ item.setValid(true); item.setRequired(false); item.setVisible(false);}function enable(item){ item.setRequired(true); item.setVisible(true);}
Oh Or reading your replies more carefully, i understand that validations on a field and a required field are two different things. ie "a required field" is not a validation criteria ? thanks for your time and patience.
yes but not in the case of replicant. .
Oh Or reading your replies more carefully, i understand that validations on a field and a required field are two different things. ie "a required field" is not a validation criteria ? y is a replicant. cont/y[1]/(required field item).setRequired(false) sets the required field for the first instances as false. however, how can i find the number of instances that are present in the DCT. ie say the user selects y( x= off), fills in 2/3 instances and switches back to x=on. In this case required fiedls for instances 2 and 3 are not false. any suggestions?thanks for your time and patience.
For an instance of x (there is only one), there is either an instance of y or an instance of z. multiple instances of y are allowed (y is a replicant), there can be only one instance of z( z is a container). if the user selects 2/3 instances of y, and then changes his mind n chooses z, i have to (remove/invalidate) all instances of y. Yes, getting the length(number of instances of y) is a possible solution. thanks