function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SolidLucasSolidLucas 

setting limits into fields visualforce

i've created a visualforce that have some filters that i want to set a limit to have at least 3 caracters to do a search, someone could explain me how do i achieve that? 

thanks!
ManjunathManjunath
Hi,

As you would be holding the filter value in an varible, befor entering in the serach check for the size of it. If it is less than 3 then give out an apex mage using the

ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
ApexPages.addMessage(myMsg);

Make sure to put <apex:pageMessages /> in VF page.

Option 2
Using javascript.

Regards,
MCS
BalajiRanganathanBalajiRanganathan
you could do this in two ways

1) using Javascript alert. you can use $Compnoent Global variable to get the value. you can have onlink javascript fuction which shows
    alert using the field value. refer below link on how to use $Component global variable.
https://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_component.htm

2) using validation in the controller action method and display error using <apex:pageMessages />

    if (String.isBlank(searchFiler) || searchFiler.length() < 3) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 'searchFiler is required field and should have min 3 chars'));
    }

I would prefer the approch two.