You need to sign in to do that
Don't have an account?

InputField Character limit
Is there a way to display how many characters the user has left like it does on a detail page. The issue I am running into is that when I try to save the data I put into the field the page tells me that I am over the character count. However I don't know by how much. So I am forced to guess. Thanks.
Hi,
Yes you can achieve this through the JavaScript.
Here is the javascript function:-
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
It worked well. I was wondering however, I noticed that you hard coded the limit into the code. Is there a way to get the limit from the field that the input tag is attached to? Also when I use the detail page it seems to count hard enters in the strings as two characters. Is there a way to do that in the JavaScript?
OK I found a way to make spaces count for two. But I am Having trouble getting the java script to work. I still would like to know if there is a way to get the limit value from the field possible using schema. Also I am having trouble getting the Javascript to work on my visualforce page. It does not seem to link to my inputField. I can't seem to find the issue maybe you can see what I am doing wrong.
Visual Force Page:
Thanks . I tried. It works. However, I want to change the limit to 25 charaters. However, whatever I changed, it didn't work. Can some one help me with that ?
When you say it does not work what do you mean? Can you elaborate on the issue. Is there an error that shows up, or does it just plan not work?
It didn't have the limit of 25. The change didn't work.
Could you post your code. This may shine some line on your problem.
Try using document.getElementById(limitField) with the Id from the field that you are using.
So it should look something like this. Also if this does not work could you show me your visualforce code. That might help too.
not working correctly
Could you please post your whole visualforce page or possible just the field you are using this javascript on and the javascript.
<apex:outputPanel id="mainPanel">
<table class="fullWidthTable">
<tr>
<td>
</td>
<td class="rightAlign">
<apex:commandButton action="{!saveAndExit}" value="Save Draft" onclick="return confirm('Would you like to save your current draft of this application and exit?');"/>
<apex:commandButton action="{!prevSection}" value="Previous Section"/>
<apex:commandButton action="{!nextSection}" value="Next Section"/>
</td>
</tr></table>
<apex:outputPanel id="overviewPanel" rendered="{!currentWrapper.tabType == 'overview'}">
<h2>{!currentWrapper.tabName}</h2>
<apex:outputText value="{!fundingApp.Funding_Opportunity__r.Description__c}" escape="false"/>
<apex:outputPanel rendered="{!NOT(ISBLANK(fundingApp.Funding_Opportunity__r.Funding_Eligibility__c))}">
<h2>Eligibilitya</h2>
<apex:outputText value="{!fundingApp.Funding_Opportunity__r.Funding_Eligibility__c}" escape="false"/>
</apex:outputPanel>
<hr/><br/>
<p>Please provide the following general information regarding your application:</p><br/>
<apex:panelGrid columns="2" columnClasses="labelColumn, fieldColumn">
<apex:outputPanel >
<b>Amount Requested</b>
(Max <apex:outputField value="{!fundingApp.Funding_Opportunity__r.Funding_Maximum__c}"/>)
</apex:outputPanel>
<apex:inputField value="{!fundingApp.Funding_Requested__c}"/>
<b>Application Title - University Applicants use Technology Name, Licensee Applicants use Company Name (25 characters max. Please note that the system will omit any characters above this maximum)
</b>
<apex:inputField value="{!fundingApp.Description__c}" styleClass="writtenAnswerMultiLine"/>
<SCRIPT LANGUAGE="JavaScript">
function limitinputfiled(limitField, 25) {
if (limitField.value.length > 25) {
limitField.value = limitField.value.substring(0, 25);
}
}
</script>
</apex:panelgrid>
<h3>Primary Applicant Address</h3>
<apex:panelGrid columns="2" columnClasses="labelColumn, fieldColumn">
<apex:outputText value="Stored Addresses:"/>
<apex:actionRegion >
<apex:selectList size="1" value="{!selectedAddressRecord}" title="Select a stored address from the list to auto-fill the form below.">
<apex:actionSupport event="onchange" action="{!fillRecipientAddrFields}" rerender="rstreet, rcity, rstate, rzip, rcountry" />
<apex:selectOptions value="{!addressOptions}" />
</apex:selectList>
</apex:actionRegion>
this is my mistake. I mistyped my code.
Here is the correct version of the code that I use. Try this out.
Thanks a lot
Sure, as long as it worked I'm happy.
Since Winter '14, VF pages have HTML5 tag support. Using the html-maxlength attribute is the way to go: Make sure your apex:page has the docType="html-5.0" attribute