I am trying to get jQuery Validate to display an element with my predefined error-message. But what it does is that it replaces the predefined message with it's default value. The reason tjhat it is important for me to work is that from the backend it should be possible to translate the error-messages in an undefined number of languages.
A html snippet
<select name="brand[]" id="brand_select" class="full-width" min="1">
<option value="0"><?php echo __r('Brand','order')?> *</option>
<?php foreach ($brands as $id => $brand): ?>
<option value="<?php echo $brand->id?>" <?php echo select(__val($form_data,'brand',$n),$brand->id)?>><?php echo $brand->brand?></option>
<?php endforeach; ?>
</select>
<label class="error" id="brand_select-error" for="brand_select"><?php echo __r('This field is required!!','validation')?></label>
<?php if ($bodytypes): ?>
<select name="bodytype[]" class="full-width" min="1">
<option value="0"><?php echo __r('Body type','order')?> *</option>
<?php foreach ($bodytypes as $id => $bodytype): ?>
<option value="<?php $bodytype->id?>" <?php echo select(__val($form_data,'bodytype',$n),$bodytype->id)?>><?php echo $bodytype->body_type?></option>
<?php endforeach; ?>
</select>
<label class="error"><?php echo __r('This field is required','validation')?></label>
<?php endif; ?>
<input class="full-width" type="text" name="first_regdate[]" placeholder="<?php echo __r('First registration date','order')?> *" value="<?php echo __val($form_data,'first_regdate',0)?>" required/>
<label class="error"><?php echo __r('This field is required','validation')?></label>
The jQuery
$('#order_form_step_1').validate({
errorElement: "label",
errorPlacement: function(error,element) {
return true;
},
invalidHandler: function(event, validator) {
// 'this' refers to the form
var errors = validator.numberOfInvalids();
if (errors) {
$("div.error").show();
} else {
$("div.error").hide();
}
}
});
But somehow, whatever message I fill in in the error-divs below the input fields, jQuery overwrites them.
Having different language-files or inline buildup of the validation code are not an option. I really need the predefined messages inside the HTML labels to show up, without jQuery overwriting them.