1
votes

On a XPage how can I clear some fields when a certain radio button is pressed?

The fields are on a panel. Outside of that panel are some radio buttons. In the onChange of the radio buttons I change the render property of the panel via a viewScope variable and a partial refresh of the panel to make it disappear. This works. I just want to be able to also blank out the fields as well, else the values are saved when the users submits!

3
If you don't want the values saved, just don't bind them to a field. Right?David Navarre

3 Answers

11
votes

The SSJS equivalent of the modifyField simple action is the setValue method of the document data source; for example:

currentDocument.setValue("fieldName", null);

If someone tells you to instead call getComponent("someId").setValue(null)... don't. At first glance, that also works, but it's less efficient, fragile, and doesn't work when the target component is in a repeat control but the event component is outside the repeat. Always update the data source directly... any components bound to that data source will automatically pick up any changes you make.

1
votes

Add an event that will modify the field on onchange event and refresh the area you want to change.

<xp:modifyField    
var="document1" 
name="FIELDNAME" 
value="">
</xp:modifyField>
0
votes

Use client side onChange to run whichever of these dojo's, where the < parentID > is the id of the container the RadioButton or RadioGroup is within:

dojo.query("*[type=radio]:checked",dojo.byId(parentID)).forEach(function(node, index, nodelist){
            node.checked=false;
        });
dojo.query("*[type=checkbox]:checked",dojo.byId(parentID)).forEach(function(node, index, nodelist){
            node.checked=false;
        });
dojo.query("input",parentID).
    forEach(function(node, index, nodelist){
        node.value = "";
    })
//reset(