В моем приложении Rails 3 я удаляю <span>
, который я использую в качестве заполнителя при вводе с помощью jQuery.Если я отправляю форму и у меня появляются ошибки, форма перезагружается и отображаются ошибки.Однако для полей, в которых были ошибки, <span>
не будет очищаться при вводе, поскольку <span>
больше не находится внутри <div>
, содержащего ввод.(Это связано с добавлением field_with_errors <div>
к ошибке.) Как я могу обойти это и все еще удалить <span>
несмотря на field_with_errors?
Вот мой jQuery:
// placeholder label for text
$(function() {
$("span.holder + input").keyup(function() {
if($(this).val().length) {
$(this).prev('span.holder').hide();
} else {
$(this).prev('span.holder').show();
}
});
$("span.holder").click(function() {
$(this).next().focus();
});
});
Мой HTML с field_with_errors (jQuery не работает):
<div class="holds email">
<span class="holder">Email</span>
<div class="field_with_errors">
<input autocomplete="off" id="user_email" name="user[email]" size="38" type="text" value="">
</div>
</div>
Мой HTML без field_with_errors (jQuery работает):
<div class="holdsname">
<span class="holder">Last name</span>
<input autocomplete="off" class="inner" id="user_profile_attributes_last_name" name="user[profile_attributes][last_name]" size="18" type="text">
</div>