Important Update: Community URLs redirect issues are partially resolved. 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

Anonymous
Not applicable

Hey David, here are the answers -

  • Is there any errors being reported in the developer tools console? -- No error displayed
  • Is the text field on a tab not currently being displayed? -- Text field is not displayed when we click on No. So, that means when the text should get clear, the field is not displayed.
  • Is the text field on the layout? -- Yes, it is on layout
  • Is the text field private? -- No, it is not private

Saumya, on this:

  • Is the text field on a tab not currently being displayed? -- Text field is not displayed when we click on No. So, that means when the text should get clear, the field is not displayed.

 

The text field must be visual to the user in order for the custom object to work.  Archer doesn't load the fields for tabs that are not active/visible which means the custom object cannot see it either.

 Advisory Consultant

Anonymous
Not applicable

Ohh.. is their any other suggestion to fulfill this requirement. Because those text boxes should appear on screen only when main question is answered as Yes.

Ok, this sounds a little different.  Are you saying the text fields are hidden via a rule/apply conditional layout action?  If that's the case the custom object would work fine.

 

Can you post your custom object code so I can take a look?

 Advisory Consultant

Anonymous
Not applicable

<script>

const yesNoFieldId = 39394; // Replace with the field ID of the Yes/No field

const textFieldId = 39372; // Replace with the field ID of the text field

const yes = 52061; // Replace with the ID of the 'Yes' value in the Yes/No field

const no = 52062; // Replace with the ID of the 'No' value in the Yes/No field

 

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);

}

 

Sys.Application.add_load(function() {

   const yesNoClientId = $CM.getFieldById(yesNoFieldId).clientId;

   

   $('div[id^="' + yesNoClientId + '"]').change(function() {

     const yesOrNo = $CM.getFieldValue(yesNoFieldId);

 

if (yesOrNo !== null && yesOrNo[0] === no + ':0') {

setTextField(textFieldId, '');     }

   });

});

</script>

Anonymous
Not applicable

Hey David  ,

 Were you able to look into my code

It's possible that your .change() might not be firing.  Add a console.log() inside of a change to see if it is indeed firing.

 Advisory Consultant

Anonymous
Not applicable

Is this the correct way of writing it ?

 

<script>

const yesNoFieldId = 39394; // Replace with the field ID of the Yes/No field

const textFieldId = 39372; // Replace with the field ID of the text field

const yes = 52061; // Replace with the ID of the 'Yes' value in the Yes/No field

const no = 52062; // Replace with the ID of the 'No' value in the Yes/No field

 

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);

}

 

Sys.Application.add_load(function() {

   const yesNoClientId = $CM.getFieldById(yesNoFieldId).clientId;

   

   $('div[id^="' + yesNoClientId + '"]').change(console.log()

function() {

     const yesOrNo = $CM.getFieldValue(yesNoFieldId);

 

if (yesOrNo !== null && yesOrNo[0] === no + ':0') {

setTextField(textFieldId, '');     }

   });

});

</script>

Not exactly

$('div[id^="' + yesNoClientId + '"]').change(function() {
console.log("Field has changed");
const yesOrNo = $CM.getFieldValue(yesNoFieldId);
if (yesOrNo !== null && yesOrNo[0] === no + ':0') {
console.log("Clearing Text Field");
setTextField(textFieldId, '');
}
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I added two console.log() lines, one to tell you that the change indeed fired and the other one that the criteria has been met and clearing the text field.

 

Make sure you have your browsers developer tools open to the Console tab to see the output.

 Advisory Consultant

Anonymous
Not applicable

 Hard luck!!

Not working for me...

 

Any other suggestions ?