Important Update: Some Community URL Redirects are Under Maintenance. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Clear out text field based on value list options

Anonymous
Not applicable

There are two fields as below:

1. Please choose Yes/No,

2. If Yes, please specify, (text box)

 

If i chose "Yes" for 1, 2 gets displayed. 

 

I want to clear out text box 2 if Yes is changed to No for 1.

39 REPLIES 39

You're welcome. Happy to help!

Hi Geoff ~ It worked lik a charm!  Thank you again for your assistance!

 

Frank

You're welcome. Happy to help!

Hi Geoff Taylor‌,

 

Thanks for the code.

I have to clear two text fields when the page loads on a particular layout.the application using Advanced workflow.

What change should I make to the code?

Try adding this code to the specific layout where you want to clear the text fields. (I don't have an advanced workflow application to test this, but I think it will work.)

 

Note that it will clear the text fields as soon as the page loads, so there's no opportunity for a user to prevent it.

 

<script>
const textFields = [21583, 21584];

function setTextField(fld,val) {
let textFieldAttributes = new Array();

textFieldAttributes.push({
enabled: true,
emptyMessage: '',
validationText: val,
valueAsString: val,
lastSetTextBoxValue: val});

const textFieldAttributesSerialised = Sys.Serialization.JavaScriptSerializer.serialize(textFieldAttributes[0]);

$('input[id$="'+ fld +'c"]').val(val);
$('input[id$="'+ fld +'c_ClientState"]').val(textFieldAttributesSerialised);
}

Sys.Application.add_load(function() {
textFields.forEach(function(fld) {
setTextField(fld, '');
});
});
</script>

Fsantana
Contributor III

Hi Geoff,

Trying to update the custom object you supplied to clear numeric fields. I need to clear three fields but it doesn't seem to trigger the clear.

 

<script>
  const numericFieldId = [23244, 23111, 23112];
  const vlFieldId = 23104;
  // If the values list field contains any of the values in the array below, set the numeric field to blank.
  // The values are specified by ID. Append ':0' to each value ID so that we can write simpler code to do the comparison.
  const clearFieldOnValues = ['82807:0'];

  function setNumericField(fld, val) {
    // A numeric field's <input> element has 'minValue' and 'maxValue' attributes.
    // Get the existing attribute values so they can be reused when setting the numeric field's value.
    const attrs = Sys.Serialization.JavaScriptSerializer.deserialize($('input[id$="'+ fld +'c_ClientState"]').val());
    const minVal = attrs.minValue;
    const maxVal = attrs.maxValue;

    let numericFieldAttributes = new Array();

    numericFieldAttributes.push({
      enabled: true,
      emptyMessage: '',
      validationText: val,
      valueAsString: val,
      minValue: minVal,
      maxValue: maxVal,
      lastSetTextBoxValue: val
    });

    const numericFieldAttributesSerialised = Sys.Serialization.JavaScriptSerializer.serialize(numericFieldAttributes[0]);

    $('input[id$="'+ fld +'c"]').val(val);
    $('input[id$="'+ fld +'c_ClientState"]').val(numericFieldAttributesSerialised);
  }

  Sys.Application.add_load(function() {
    const vlClientId = $CM.getFieldById(vlFieldId).clientId;
    const radioButtons = $('input[id^="' + vlClientId + '"]');

    /* The handler must be attached to each radio button's change event,
    so iterate over the radioButtons object and attach the handler to the
    change event of each <input> element. */
    for (let key in radioButtons) {
      if (radioButtons[key] instanceof HTMLInputElement) {
        let rbId = radioButtons[key].id;
        $('input#' + rbId).change(function() {
          let selectedValue = $CM.getFieldValue(vlFieldId);

          /* if (selectedValue !== null && clearFieldOnValues.indexOf(selectedValue[0]) !== -1) */ {
            setNumericField(numericFieldId, '0');
          } 
        });
      }
    }
  });
</script>

 

Thanks,

Frank

Anonymous
Not applicable

Hi David Petty, could you please tell me datafeed process to clear out the values. It would be really helpful.

Saumya, for a data feed to just need to create a new field on the Source Definition tab, set it as Static with not value.  Map that field to the item of the values list and make sure the option for the mapped field is configured to allow empty values.

 Advisory Consultant

Anonymous
Not applicable

yea but my worry is that there are 10 main questions and 10 text fields. If there's only one main question on which all other 10 fields are dependent then I just have to create one report with filter option as 'question 1 equals No' and then can execute datafeed on the basis of it..  but here I am not sure how I gonna apply filters on the report

Hi Geoff, I tried converting the code you pasted above to use radio buttons (using radio button code from other examples on this page) but I'm running into problems. Do you have a version of the code that uses radio buttons? (I'm referring to the code you pasted on September 3, 2019 at 3:49).

 

Thanks,

Jeff

 

I've made progress building custom object code to set a text field to a specific value when using radio buttons for a values list, but I am experiencing two issues that I could use help resolving:

 

1) sometimes the code does not find a match even though I am testing using the same values list and textbox.

2) the code only seems to execute once, not every time I change the values list value.

3) when I find a match for the values list and the call to the function to set the value of the textbox executes, the text box is never set to the value that I want. (I've confirmed the textbox is public and is on the layout, although I do want to enable a rule and action to hide the textbox and set the value of the textbox when the textbook is hidden).

4) I am running Archer 6.8

 

Here is the code:

 

<script>

  const textFieldId = 26134;

  const vlFieldId = 25732;

  // If the values list field contains any of the values in the array below, set the numeric field to blank.

  // The values are specified by ID. Append ':0' to each value ID so that we can write simpler code to do the comparison.

  const clearFieldOnValues = ['35341:0', '35528:0'];

 

function setTextField(fld,val) {

     var textFieldAttributes = new Array();

 

     textFieldAttributes.push({

          enabled: true,

          emptyMessage: '',

          validationText: val,

          valueAsString: val,

          lastSetTextBoxValue: val});

 

     var textFieldAttributesSerialised = Sys.Serialization.JavaScriptSerializer.serialize(textFieldAttributes[0]);

 

     $('input[id$="'+ fld +'c"]').val(val);

     $('input[id$="'+ fld +'c_ClientState"]').val(textFieldAttributesSerialised);

console.log("in set text function");

console.log("fld = ", fld);

console.log("val = ", val);

}

 

  Sys.Application.add_load(function() {

    const vlClientId = $CM.getFieldById(vlFieldId).clientId;

    const radioButtons = $('input[id^="' + vlClientId + '"]');

 

    /* The handler must be attached to each radio button's change event,

    so iterate over the radioButtons object and attach the handler to the

    change event of each <input> element. */

console.log("before for loop");

    for (let key in radioButtons) {

      if (radioButtons[key] instanceof HTMLInputElement) {

        let rbId = radioButtons[key].id;

        $('input#' + rbId).change(function() {

          let selectedValue = $CM.getFieldValue(vlFieldId);

 

          if (selectedValue !== null && clearFieldOnValues.indexOf(selectedValue[0]) !== -1) { console.log("calling settextfield");

            setTextField(textFieldId, 'Jeff');

          } 

        });

      }

    }

  });

</script>

Thanks,

Jeff