I know I could completed this on the front end or with some JS, but I am already using the required attribute on the apex:inputField for all the other fields, so it would be nice if I could make this consistent. Here are the two fields:

                <div class="input-group">
                    <label>{!$ObjectType.Asset.fields.SerialNumber.label}<span class="required-ast">SN or Order Number is required</span></label>
                    <apex:inputField value="{!asset.SerialNumber}" required="true"/>

                <div class="input-group">
                    <label>{!$ObjectType.Asset.fields.Order_Number__c.label}<span class="required-ast">SN or Order Number is required</span></label>
                    <apex:inputField value="{!asset.Order_Number__c}" required="true"/>

and here is the submit button, if relevant:

                <div class="input-group">
                    <apex:commandButton action="{!save}" value="Submit"/>
  • 1
    add a check in your save() method to see if any of them is filled in? – Novarg Mar 9 '16 at 14:44
  • 2
    @Novarg. The downside to that being that he will then need to use pagemessages to tell the user they need to complete one or the other of the fields. jQuery validation would be a cleaner solution and would show that one or the other of the two fields is required. – crmprogdev Mar 9 '16 at 14:46
  • So, I think I will need to run an onclick on the commandButton, but is there a way to pass in the click event into the js function? – notthehoff Mar 9 '16 at 14:57
  • @Novarg any thoughts? – notthehoff Mar 9 '16 at 15:20
  • 1
    @notthehoff, you can easily pass along the click event like this <apex:commandButton value="Submit" onclick="yourJSFunction(event)" /> – RenegadeCoder Mar 9 '16 at 19:40

Why dont you add a validation rule?

Criteria can be like:

| improve this answer | |
  • It is coming in from a vf page form. So, no matter the validation on the field from within sf, my understanding is that it does not impact validation on the front end. – notthehoff Mar 9 '16 at 14:56
  • Nope, If you add validation rule on your object it will validate your data no matter from where its coming from i.e. page , api import anything .... – AtulRajguru9 Mar 9 '16 at 15:01
  • So, how would the person who is filling out the form know that they have entered bad data? – notthehoff Mar 9 '16 at 15:18
  • I will call them and tell them about wrong data :D.... sorry i was just tryinf to be funny ... try validation rule you will get it .. just 5mins job – AtulRajguru9 Mar 9 '16 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.