Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Would <a href="https://login.salesforce.com/help/doc/en/fields_useful_field_validation_formulas.htm" rel="nofollow">Validation Rules</a> work for you? You could have a Validation rule for each dynamically required field that takes the checkbox into consideration. That would take care of the server-side validation, but you would need to take care of the client side separately if you're using anything other than Apex Classes and Extensions (like JavaScript or jQuery) to submit the data.</p> <p>To take advantage of the default CSS Styling Visualforce provides, add the "error" class to the input element if the user tries to save without entering a value.</p> <p>Here's an code snippet of how I would approach the client side validation (using jQuery in noConflict mode as <code>j$</code>):</p> <pre><code>// check required fields j$(RequiredFields).each(function(index,field) { if(!(field.val() &amp;&amp; field.val() != "" &amp;&amp; field.val() != "--None--")) { field.addClass("error"); RequiredFieldsInError.push(field); } else { field.removeClass("error"); } }); if(RequiredFieldsInError.length &gt; 0) { var RequiredFieldLabels = []; j$(RequiredFieldsInError).each(function(index,field){ var RequiredFieldLabel = j$("label[for$="+j$(field).attr('id')+"]").html().trim(); RequiredFieldLabels.push(RequiredFieldLabel); field.after("&lt;div id='"+field.attr("id")+"_error' class='errorMsg' &gt;"+RequiredFieldLabel+" is Required.&lt;/div&gt;"); }); if (RequiredFieldLabels.length &gt; 1) { RequiredFieldLabels[RequiredFieldLabels.length - 1] = "and " + RequiredFieldLabels[RequiredFieldLabels.length - 1]; } j$("#ErrorSummary") .html(RequiredFieldLabels.join(", ")+" "+(RequiredFieldLabels.length &gt; 1 ? "are" : "is a")+" required field(s). ") .css("color","#CC0000"); return; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload