3

currently in my visualforce page I have an html input:

<input class="tb1" data-val="true" data-val-length="First Name should be less than 50 characters." data-val-length-max="50" data-val-regex="First name can only contain alphabets, hyphen and apostrophe." data-val-regex-pattern="^[a-zA-Z &#39;-]+$" data-val-required="First Name is Required" id="FirstName" maxlength="50" name="FirstName" style="width:285px;" type="text" value="" />
                        </td>

I want to change this to

<apex:inputfield value="{!c.FirstName}" 

but I don't want to lose the attributes listed in the html input such as data limit, or type, etc. The apex:inputfield's attributes are limited, and the error message for the required validation isn't the way I want it to look.

Is there any way I can incorporate both of these together? Thanks

3

Visualforce now supports pass-through attributes so adding a html- prefix to each of your attributes should work:

<apex:inputfield value="{!c.FirstName}" html-data-val="true" html-data-val-length="First ...
| improve this answer | |
  • Hi Keith, I tried what you suggested and visualforce is accepting this to save. However, the validation rudes in the html attributes such as text only, etc are not applying to the inputfield. – Adi Dec 10 '14 at 21:51
  • @Adi Attributes like data-val-length require some 3rd party code such as jQuery unobtrustive validation - they are not native to the browser. All Visualforce can do is output the attributes - you have to wire-up logic that uses them. – Keith C Dec 10 '14 at 22:47

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.