Laravel 5.7-自定义验证消息欧芹

时间:2019-01-31 07:29:54

标签: jquery parsley.js parsley

我正在开发一个系统,并且在我的系统中实现了香菜。当某些字段不符合要求时,我想更改验证消息。

For example

Name Input
Description Input
Rate Input

缺少所有字段时,我的欧芹验证工作正常。提交表单后,我想在“费率输入”字段中将验证更改为“仅十进制”。

我现在所拥有的是,当我单击查看按钮时,将显示模态。所有信息将在模态内部列出,在底部,我具有编辑按钮。

当我单击编辑按钮时,所有标签/ p将更改为输入字段(我在这里使用了jquery)。

模式

<form id=".." data-parsley-validate novalidate>

</form>

jQuery

Appending
$('#wht_rate_view').append('<input type="text" class="form-control" name="wht_rate" id="wht_rate" value="'+wht_rate_view+'" data-parsley-error-message="sss" required/>');
 $('div').on('submit','form#update-wht-form',function(e){
        var formData = $(this).serialize();
        swal({
                title: "Are you sure?",
                text: "Once saved, you will not be able to change your key information!",
                icon: "warning",
                buttons: true,
                dangerMode: true,
              })
              .then((willSave) => {
                if (willSave) {
                  $.ajaxSetup({
                     headers: {
                         'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                     }
                  })
                   $.ajax({
                     url: '/configurations/taxes/updateWHT',
                     type: "POST",
                     data: formData,
                     beforeSend: function() {
                        $('.update-wht').attr('disabled', 'disabled');
                     },
                     success: function(response) {
                         if (response != '') {
                            $('#get-wht-table').DataTable().destroy();
                            getWHTTable();
                            $('#update-wht-form').trigger("reset");
                            swal("Withholding Tax has been updated!", {
                              icon: "success",
                            });
                            $('#view-wht-details').modal('hide');
                         }
                     },
                     complete: function() {
                        $('.update-wht').removeAttr('disabled');
                     }
                  });
                } else {
                  swal("Save Aborted");
                }
              });

          e.preventDefault();
          return false;


    });

注意:我在消息中使用了sweetalert

问题:如何更改验证消息?

1 个答案:

答案 0 :(得分:0)

使用data-parsley-<constraint>-message="my message"属性,其中<constraint>应该是约束的名称(例如required)。

相关问题