Input value doesn't display. How is that possible?

后端 未结 13 2083
后悔当初
后悔当初 2021-02-04 23:54

This must be something utterly stupid that I\'ve done or am doing, but I have an input with a value attribute that simply isn\'t being displayed:

相关标签:
13条回答
  • 2021-02-05 00:26

    I had the same problem of @Rob Wilkerson, a onchange() was cleaning the value of the input with "", so i changed to 1. Such a dumb problem!

    HTML
    <input class="form-control inputCustomDay" type="text" id="txtNumIntervalo" onkeyup="changeTipoOptions()" value="1" min="1" />
    
    Jquery
    $("#txtNumIntervalo").val(1);
    
    0 讨论(0)
  • 2021-02-05 00:29

    Had a similar problem with input value retrieved via ajax, correctly set and verifiable via browser console, but not visible. The issue was another input field having the same id, and it was not evident because of several JSP files included, many of them having forms.

    0 讨论(0)
  • 2021-02-05 00:29

    For me it was wrong number format: Chrome expected "49.1", but ASP.NET passed "49,1", and it just didn't display!

    <input type="number" value="49,1"/>    // Should have been 49.1 !!!
    
    0 讨论(0)
  • 2021-02-05 00:31

    For my side, it was a problem only for Firefox.

    I resolved by adding the attribute autocomplete="off" in the input field.

    <input type="text" value="value must appear" autocomplete="off"/>
    
    0 讨论(0)
  • 2021-02-05 00:35

    Are you confusing the uses of the 'default' and the 'value' parameters for $html->input()?

    If you're are using 'default' => $product['Product']['make'] and $this->data is present, the field will not be populated. The purpose of the 'default' parameter is to display a default value when no form data ($this->data) is present.

    If you want to force display of a value, you should use the 'value' parameter instead. 'value' => $product['Product']['make']

    0 讨论(0)
  • 2021-02-05 00:38

    I even set autocomplete to "off" with no result. I ended up putting the next jquery snippet at the document.ready event.

    myForm.find("input").each((i, el) => {
      $(el).val($(el).attr("value"));
    });
    

    Adittionally, this would be the equivalent in pure es2015:

    document.querySelectorAll("myForm input").forEach(el => {
      el.value = el.getAttribute("value");
    });
    

    If your not using a precompilor like Babel and you need compatibility for old browser's versions, change the "(el) =>" for "function(el)". I tried both codes in my scenario and worked fine.

    0 讨论(0)
提交回复
热议问题