1

maxlength attribute in is not working. Is there any alternative ways for this isuue or any suggestion?

Reffrence: https://developer.salesforce.com/docs/component-library/bundle/lightning:input/example#lightningcomponentdemo:exampleInputNumber

  • can you should me with your code and some screen shot? – Sagar Hinsu Oct 15 '18 at 6:23
2

You could specify a minimum and maximum value. It won't prevent input values outside the range, but will highlight it with a red error message:

<lightning:input label="Some Field" max="9999" min="0" />

Be sure to check validity before saving if you use this technique.

  • Thanks for reply, If I enter decimal value it's fire error, so I used step attribute. But I want to enter value in 3.2(Ex.99.25) format for percent field. Do you have any suggetion for percent field? – Fesal Suritawala Oct 15 '18 at 7:25
1

I handle through javascript handler, here is code:

--Component--

<aura:component >
    <lightning:input type="number" aura:id="number" name="input1" 
                     label="Enter a number" maxlength="3" onchange="{!c.CheckLength}"/>
</aura:component>

-- Controller.js----

({
    CheckLength : function(component, event, helper) {
        var val = component.find("number").get('v.value');
        if(val.length > 3){
            var comp = component.find("number");
            comp.set('v.value',val.substring(0,3));
        }
    }
})
0

Its been a while now, but, the lightning:input component now prevents entering additional characters when the set limit has been reached and optionally displays an error message:

<lightning:input maxlength="255" required="true" label="Subject" name="Subject" value="{!v.subjectValue}" messageWhenValueMissing="Complete this field." messageWhenTooShort=" " />

Example (when empty and field is required):

enter image description here

Example (When limit reached): enter image description here

**the char counter is custom, added for visibility purposes.

  • It still doesn't work for number type – Vinod Rondla Apr 25 at 20:35

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.