Remove Validation from Required Field Conditionally

SuiteCRM Version 7.10.11

Via Custom JS in Opportunities Module, when sales stage is Prospecting (default) i have added following code in order to make Expected Close Date as NOT Mandatory.

  if($(this).val() == "Prospecting") {
  else {
     addToValidate('EditView', 'date_closed', 'date', true,'Expected Close Date' );
// call on load 


Apparently it should work as not requiring the Expected Close Date on Create Opportunity (as Prospect is default stage) yet it does not work and still the date is Mandatory.

It only works when i Change the Dropdown from Prospect to Another Status and then back to Prospect. NOT on the Load or First Go. Is it related to the validate[“EditView”] object?

This PR adds a validation, and it seems to do 2 things: add a CSS class “required”, and call the Javascript addToValidate function.

Maybe you can check that CSS class in your case?

REMOVING the class=“required” from the LABEL span element worked for me. Following is the LABEL html and note the span class which needs to be removed to make it NOT Required.

<div class="col-xs-12 col-sm-4 label" data-label="LBL_DATE_CLOSED">
Expected Close Date:<span class="required">*</span></div>

If you check the browser’s console, you’ll find the theme creates an different object as the label. That object is the one that receives the validation star. The default label of the field is never displayed. Now, regarding the created label object, is hard to find the name. To modify it I use my field name to get the parent. This is what I use to add the star. It might give you an idea on how to remove it.

// adding star to label
$('#myfield').parent().parent().children().first().html('{$mod_strings['LBL_MYFIELD']}: <span class=\"required\">*</span>');	



I can get that Element via following Code.


One thing that is apparently causing issue is that the removeFromValidate function is not available when the document ready is called. The reason being that validation code is appended in the document in the last, as checked via inspecting dom elements.