Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2019-07-08 09:50 AM
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.
2019-07-17 09:47 AM
Hey David, here are the answers -
2019-07-17 09:51 AM
Saumya, on this:
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
2019-07-17 10:29 AM
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.
2019-07-17 10:46 AM
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
2019-07-17 11:05 AM
<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>
2019-07-18 09:00 AM
Hey David ,
Were you able to look into my code
2019-07-18 10:05 AM
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
2019-07-18 10:19 AM
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>
2019-07-18 10:23 AM
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
2019-07-18 11:09 AM
Hard luck!!
Not working for me...
Any other suggestions ?