Topic: Pre-filling Input Fields with Javascript Leaves label blocking field content

mark.sauer pro asked 6 years ago


On some forms, I am pre-filling data as follows: $("#fieldId").val(myValue); This works, but the field label does not move out of the field content area and leaves the content blocked. Once you tab through the fields, the script then seems to know that there is content in the field and moves up. The desired behavior is to have the label move up when I populate the value with script. Can I force this perhaps with a JQuery event trigger?

mark.sauer pro answered 6 years ago


Problem solved. I created a function as follows:
function fixFieldState(inputField) {
    $(inputField).trigger("focusin");
    $(inputField).trigger("blur");
}
I can then call the following on any field after setting the value and the state of the field will be corrected. Not a great solution, but it does work. fixFieldState($("#field_id"));

Alan van Buuren pro commented 4 years ago

Thnx, after 2 years, the problem persist.


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Specification of the issue

  • User: Pro
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No