Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
User avatar
By amosbatto
#812678
Here is some sample JavaScript that you can use to outline empty fields with a blue border:
Code: Select all
//set the IDs of the fields to be checked if empty:
var aFieldsToCheck = ['name', 'address', 'clientType', 'taxIncluded', 
  'workStartDate', 'userResponsible']; 

function checkIfEmpty(fieldId, val) {
  //if in array of fields that shouldn't be empty:
  if ($.inArray(fieldId, aFieldsToCheck) != -1) {
    var fieldType = $("#"+fieldId).getInfo()['type']
    if (fieldType == 'checkbox') {
      if (val == '0' || val == '"0"') 
        $("#"+fieldId).getControl().closest('div').css('backgroundColor', 'blue');
      else
        $("#"+fieldId).getControl().closest('div').css('backgroundColor', ''); //default
    }
    else { //any other type of field but checkbox:
      if (val == '') 
        $("#"+fieldId).getControl().css('borderColor', 'blue');
      else 
        $("#"+fieldId).getControl().css('borderColor', ''); //set back to default color
    }
  }
}
    
function checkAllFields() {
  for (idx in aFieldsToCheck) {
    var fieldId = aFieldsToCheck[idx];
    var val = $("#"+fieldId).getValue();
    checkIfEmpty(fieldId, val);  
  }
}

checkAllFields(); //call when the DynaForm loads

var formId = $("form").prop("id"); 
$("#" + formId).setOnchange(function(fieldId, newVal, oldVal) {
  checkIfEmpty(fieldId, newVal);
});

Here is a sample form to check the code:
(7.13 KiB) Downloaded 253 times
Note that this code doesn't work for checkgroups or grids.

In the rapidly evolving world of online sports be[…]

STEPN integrates social networking and games that […]

Cenforce 150 is a medication used to cope with a c[…]

What's SAP FICO?

Trustworthy and skill-building, each of these actu[…]