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

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Object Issue with clearing text fields using radio buttons

Fsantana
Contributor III
Hi Folks,

I created a custom object which clears two text fields when selection Yes on a value list field using a radio button. The issue I am having is when you select Yes or No it will clear the text fields. How do I fix my code to not clear the fields when you select No? Any help would be appreciated.

Thanks, Frank

Below is the code.

 

<script type="text/javascript">
const textFieldId = [112960,112962];
const vlFieldId = 112961;
const clearFieldOnValues = ['421679: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);
}
Sys.Application.add_load(function()
{
var vlClientId = $CM.getFieldById(vlFieldId).clientId;
var radioButtons = $('input[id^="' + vlClientId + '"]');
 
for (let key in radioButtons) {
  if (radioButtons[keyinstanceof HTMLInputElement) {
  let rbId = radioButtons[key].id
 $ ('input#' + rbId).change(function() {
  var selectedValue = $CM.getFieldValue(vlFieldId);
  if (selectedValue !== null && clearFieldOnValues.indexOf(selectedValue[0]) !== 0)
{
textFieldId.forEach(function(textFieldId) {
setTextField(textFieldId , '');
});
}
});
}
}
});
</script>
3 REPLIES 3

DavidPetty
Archer Employee
Archer Employee

@Fsantana,  would either add debugger or console.log(selectedValue); before this line, if (selectedValue !== null && clearFieldOnValues.indexOf(selectedValue[0]) !== 0) { to see what value you're getting.

 Advisory Consultant

values prior to change.

co_issue1.jpg

Selected the 'No' value console log shows ['421724:0']

co_issue2.jpg

Thanks.  I think what's missing is that you need to see if the right radio button is checked.  You can incorporate something like this, https://stackoverflow.com/a/8725267

 Advisory Consultant