Validate textbox using js

Hello,

How can i validate the text box is required for following scenerio, assume that if two text box having if both are empty validation error want to display, if any one is not empty should not validate.

Thanks,
Karthi

Hi Karthi,
You can add and remove validation based on some condition in JavaScript.

You can use - addToValidate and removeFromValidate function in js.

Have a look at

http://forums.sugarcrm.com/f6/question-about-addtovalidate-removefromvalidate-usage-59880/

Regards,
Alpesh

1 Like

Hello,

Thanks

Hi,

Also you can use some custom javascript code to edit view check textbox values in when save button is clicked.

for example…

$(document).ready(function(){

$('#SAVE_HEADER').removeAttr('onclick').click(function(){

if(/some condition to check validation){
/

some code when validation fires.

*/
}
else{
var _form = document . getElementById(‘EditView’);
_form.action.value = ‘Save’;
if (check_form(‘EditView’))
SUGAR . ajaxUI . submitForm(_form);
return false;
}
})
});

The easiest way is to just add the javascript to your vardefs of the field:

https://gunnicom.wordpress.com/2015/09/21/suitecrm-sugarcrm-6-5-add-custom-javascript-field-validation/