2

I have a VF page built mostly out of html tags, and associated Jquery that has been uploaded to static resources and included in the VF page using <apex:include script>

I want to change the html <input> to <apex:inputfield> which is simple and works fine using my custom controller to data bind values.

However, the attributes and validation in the html input don't carry over to the apex inputfield, even when I append them with 'html-' in front, as I was suggested to do on here earlier. For example:

<input class="tb1" data-val="true" data-val-length="Last Name should be less than 50 characters." 
data-val-length-max="50" data-val-regex="Last name can only contain alphabets, hyphen and 
`apostrophe."  type="text" value="" />`

has been changed to:

<apex:inputfield html-data-val="true" data-val-length="Last Name should be less than 50 
characters." html-data-val-length-max="50" html-data-val-regex="Last name can only contain 
alphabets, hyphen and apostrophe."  value="{!c.LastName}" />

When I try to save without a value in the inputfield, the standard Salesforce 'Error: You must enter a value' appears. I want to override this with the html/ jquery error message that appears for the <input> .

I have also tried using <apex:message> to have a custom error message and also tried using <apex:inputtext> but neither seem to work either.

Any suggestions? Thank you

2 Answers 2

1

You can use the jQuery validatate plug-in with visualforce which should solve all the issues that you mention. There's an example of using it on Wes Nolte's blog, The Silver Lining.

0
1

Give them IDs and use the jquery on your VF page. Write all your validation logic under script tag and you will be all set. It is no different than a simple html page.

You can remove the attribute required = true from each of your tag. I hope then you will be able to overwrite with your custom validation warnings.

2
  • Hi, what do you mean give them IDs? Could you give me an example please?
    – Adi
    Dec 15, 2014 at 16:35
  • @Adi For example. <apex:input id="nameField" />
    – Superman
    Dec 15, 2014 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .