如何在不提交表单的情况下触发错误消息,因为当我单击输入字段而未键入内容时,如果单击输入字段,则会触发验证错误,指出此字段不能为空。我尝试使用' data-parsley-trigger =" keyup"'但仅在输入字段中输入内容时才有效
例如,如果您单击此网站上的标题字段https://deals.jumia.cm/en/posts/new并且未在字段中键入任何内容,则单击标题字段,它将触发验证错误
<form method="post" class="ad-form" enctype="multipart/form-data" data-parsley-validate >
<label for="title">Title</label>
<input type="text" id="title" name="title" placeholder="Title" required="required" data-parsley-maxlength="255" data-parsley-maxlength-message="Title can't have more than 255 signs." data-parsley-required-message="Please enter a title." data-trigger="focus" data-toggle="popover" data-content="Keep the title short and clear. Do not write the price in it or any information that is not relevant." data-parsley-validate-if-empty data-parsley-trigger="keyup"/>
<script>
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
$('.popover-dismiss').popover({
trigger: 'focus'
})
</script>
<label for="category">Category</label>
<select id="Category" name="category" required="required" data-parsley-required-message="Please select a Category." data-level="0">
<option value="">Select Category</option>
</select>
<label for="subcategory">Subcategory</label>
<select id="Subcategory" name="subcategory" data-parsley-required-message="Please select a subcategory.">
<option value="">Select Category first</option>
</select>
</form>
答案 0 :(得分:1)
使用data-parsley-trigger="blur"
和data-parsley-validate-if-empty=true
。