put Custom Message in PT-BR in required field

2

Assign Required="true" to a password field, but the message is in English, as can be seen in the image below:

IwantedtocustomizethismessagebyleavingitinPT-BR

<divclass="form-group">
        @Html.LabelFor(model => model.Senha, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Senha, new { htmlAttributes = new { @class = "form-control senha", id = "Senha", required="true" } })
            @Html.ValidationMessageFor(model => model.Senha, "", new { @class = "text-danger" })
        </div>
    </div>

  •     
  • asked by anonymous 22.01.2017 / 15:12

    1 answer

    2

    This error is related to the required attribute of html5. This is the default message. You can change it via javascript:

    <form id="form2">
        <input type="text" required />
        <input type="submit">
    </form>
    
    
    $('#form2 input[type=text]').on('change invalid', function() {
        var textfield = $(this).get(0);
    
        // 'setCustomValidity not only sets the message, but also marks
        // the field as invalid. In order to see whether the field really is
        // invalid, we have to remove the message first
        textfield.setCustomValidity('');
    
        if (!textfield.validity.valid) {
          textfield.setCustomValidity('Campo Obrigatório');  
        }
    });
    

    link

        
    22.01.2017 / 20:51