Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7814403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:10:58+00:00 2026-06-02T05:10:58+00:00

I’m working with a custom form in Salesforce and have come across a stumbling

  • 0

I’m working with a custom form in Salesforce and have come across a stumbling block in making optional fields turn into required fields dynamically if a certain checkbox is checked.

For example, if a user checks the Electronic Funds Transfer option for payment, all of the fields related to EFT should then become enabled and Apex should display them as required fields (as in not optional).

I am currently enabling the fields using jQuery, but am having a difficult time finding examples of how to change the fields into Apex-required fields.

Thanks for any help or leads on solving this issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:10:59+00:00Added an answer on June 2, 2026 at 5:10 am

    Would Validation Rules 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.

    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.

    Here’s an code snippet of how I would approach the client side validation (using jQuery in noConflict mode as j$):

    // check required fields
    j$(RequiredFields).each(function(index,field)
    {
        if(!(field.val() && field.val() != "" && field.val() != "--None--")) { field.addClass("error"); RequiredFieldsInError.push(field); } 
        else { field.removeClass("error"); }
    });
    
    if(RequiredFieldsInError.length > 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("<div id='"+field.attr("id")+"_error' class='errorMsg' >"+RequiredFieldLabel+" is Required.</div>");
        });
    
        if (RequiredFieldLabels.length > 1) {
            RequiredFieldLabels[RequiredFieldLabels.length - 1] = "and " + RequiredFieldLabels[RequiredFieldLabels.length - 1];
        }
    
        j$("#ErrorSummary")
            .html(RequiredFieldLabels.join(", ")+" "+(RequiredFieldLabels.length > 1 ? "are" : "is a")+" required field(s). ")
            .css("color","#CC0000");
    
        return;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.