Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..

cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript Validator Triggered by Change in Text Field

JeffLamb1
Contributor III

I'm trying to create a custom object that will trigger on a change to the contents of a text (not text area) field. The goal is to display a warning when the contents of the text field do not match a specific format. I can get the function to fire based on other field types (like a date/time field or a dropdown values list field) but can't get it to trigger based on a change to a text field.

The code below shows what I'm trying to do. The validation function is just a simplified example. The first event handler is triggered by a change in a date/time field and is just there to verify a successful call to the validator. It works but is not what we are looking for. The second handler is an attempt to be a trigger of a change in a text field. That's what we really want, but it is not working.

Any help is appreciated.

<script type="text/javascript">
const TestDateTimeFldId = 11111; //Test Date Time
const TestTextFldId = 22222; //Test Text
 
 
function validateTextLength(fldid) {
const FieldValue = $CM.getFieldValue(fldid);
if (FieldValue.length == 19) {
return true;
} else {
return false;
}
};
 
Sys.Application.add_load(function() {
 
// Event handler for change to clock field
$('div[id*="f' + TestDateTimeFldId + 'cdp"]').change(function() { // this works
  const FieldValue = $CM.getFieldValue(TestTextFldId);
if (validateTextLength(TestTextFldId)) {
WarningAlert(FieldValue,'Valid Text - triggered by clock widget');
} else {
WarningAlert(FieldValue,'Invalid Text - triggered by clock widget');
}
});
 
 
// Event handler to change to text field. NOT WORKING YET
$('div[id*="f' + TestTextFldId + 'c"]').change(function() { // this doesn't work
const FieldValue = $CM.getFieldValue(TestTextFldId);
if (validateTextLength(TestTextFldId)) {
WarningAlert(FieldValue,'Valid Text - triggered by text');
} else {
WarningAlert(FieldValue,'Invalid Text - triggered by text');
}
});
 
});
</script>

 

 

13 REPLIES 13

Try,

$('#master_DefaultContent_rts_s8352_f23319c').blur(function() {
     if (isInvalid(23319)) {
          this.focus();
          WarningAlert(WarningMsg,'Invalid');
     }
});

 Advisory Consultant

That syntax works, but only if I take out the call to WarningAlert(). When I keep that call I still the main Archer page whited out behind the dialog box and i can't exit the dialog box.

I'm guessing that I am stuck in an infinite blur/focus/blur/focus loop where the WarningAlert() is blurring the field, which triggers the validator, which resets focus and calls the WarningAlert() function all over again. 

Also, it makes no difference whether switch the order of the calls to WarningAlert() and this.focus().

Any thoughts? Maybe there is another alert call that waits for the user to click the Ok button?

Does that code work also on a userGroup list field ?

I have tried this code and nothing happens when I leave that particular Value Popup field :

<script>
Sys.Application.add_load(function() {

$('#master_DefaultContent_rts_s10319_f30944c_s').change(function() {
alert('Exited field');
});
});
</script>