0

Trying to implement logic for lightning:input on onBlur case. I need to close this input, when it lose focus, and if I click related buttons for this lightning:input(Confirm/Cancel), want to have some custom validation logic for value in input, and if validation is ok, do something and just then close. If not, don't let input to close and show problem from input.

<lightning:input aura:id="editName"
                 maxlength="255"
                 label="Enter New name here"
                 messageWhenBadInput="bad input length"
                 onchange="{!c.onChange}"
                 onblur="{!c.onBlur}"
                 value="{!v.bufferName}"/>

In current version I'm closing input & buttons just with time delay, but it will not work ok with this additional custom validation(input will show problem, but will be close in any validity

onChange: function(component) {
    var input = component.find("editName");
    var newName = component.get("v.bufferName");
    if (newName.length > 254) {
        input.setCustomValidity("You can't type over 255-symbols name");
        input.reportValidity();
    } else {
        input.setCustomValidity("");
        input.reportValidity();
    }
},
onBlur: function(component, event, helper) {
    window.setTimeout(
        $A.getCallback(function() {
            helper.closeCardEditionForm(component); //closing part with input and buttons
        }), 100
    );
}

Any suggestion how to solve this problem or how to build all logic with this input from begining?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.