Base solution for your next web application
Open Closed

How to disable minlength and maxlength attributes? #9042


User avatar
0
AstarIT created

I have fields that need to enter a minimun and maximun of characters but also these fields can be blank or null or ' '.

In this first picture you can see the Attributes

In this secound picture I use js code to disable or delte the attributes. ` this.save = function () { debugger;

        if (!_$tenantPersonnelInformationForm.valid()) {
            return;
        }

        if ( $('#TenantPersonnel_MiddleName').val() == '')
        {
            var input = $('#TenantPersonnel_MiddleName');
            var is_name = input.val();
            if (is_name) {
                input.removeClass("invalid").addClass("valid");
                input.prop('required', false);
            }
            else {
                //input.removeClass("invalid").addClass("valid");
                //input.prop('maxlength', false);
                //input.prop('minlength', false);
                //input.removeAttr('minLength');
                //input.removeAttr('maxlength');
                //input.removeClass('minLength');
                //input.removeClass('maxlength');
            }
        }

`

As you can see in the picuture above the Atributs are gone which is what I wanted. But now, I keep getting the same error like the attributes were still there.

Can you please help us on this... where do I take the attributes. If the user does not need to fill up the field then it must be ' ' and when the user add data it has to be between that range. All help will be really appreciated. Thank you


1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi You can use custom dto validating on the backend of the application.

    https://aspnetboilerplate.com/Pages/Documents/Validating-Data-Transfer-Objects#custom-validation