2

Atribui Required="true" num campo de senha, porém a mensagem está em inglês, como pode ser vista na imagem a baixo:

inserir a descrição da imagem aqui

Queria personalizar esta mensagem deixando-a em PT-BR

    <div class="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>

obs: Não fiz no anottation, por que o atributo senha, está na classe pessoa, que é herança para a classe usuário e cliente, onde o usuário terá senha obrigatória e o cliente não possuirá senha.

1 Resposta 1

2

Este erro está relacionado com o atribute required do html5. Esta é a mensagem padrão. Você pode alterá-la 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');  
    }
});

http://jsfiddle.net/zpkKv/665/

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .