I have a custom label that prints 'Enter at least 2 characters to search.'
I would like to make the 2 a parameter that gets passed in so that the user can adjust it at their discretion. So the label would be 'Enter at least {0} characters to search.'
My issue is that this is being called from javascript so I don't have access to apex:param. Is there a workaround for this?
Here is the javascript that is inline on a VF page
window.$Label = window.$Label || {};
$Label.Alert_message_for_search_function = '{!JSENCODE($Label.Alert_message_for_search_function)}';
function validate(){
var input = document.getElementById('{!$Component.EntireRelationshipWidget.headerForWidget.searchAndClearButtons.searchBarForm.searchBar}').value;
if(input.length < 2){
alert($Label.Alert_message_for_search_function);
return false;
}
searchFunction();
return true;
}
Essentially I have a search bar that I want to impose a minimum character limit on. The javascript is called via commandButton
<apex:commandButton value="{!$Label.Search}" rerender="EntireRelationshipWidget" status="statusId" onclick="return validate();"/>
Best Answer
I ended up just adding a few lines to the javascript to manipulate the label. So the label says "Enter at least {0} characters to search." in the value section.
Then on the page javascript I used the .replace() method for strings to replace the {0} with the minLength that the user wants.