Parsley.js - change error container

前端 未结 4 976
情歌与酒
情歌与酒 2021-02-13 16:44

I want to alter the positioning of each error message. That is display the error message in the respective

. By using th
相关标签:
4条回答
  • 2021-02-13 17:21

    Parsley API has been updated. The current method is:

    data-parsley-errors-container="#your-div-id"

    See documentation here: http://parsleyjs.org/doc/index.html#psly-ui-for-field

    0 讨论(0)
  • 2021-02-13 17:30

    You can do this by overwriting Parsley's default options. (note: I'm talking about the latest version [v2.0], which I suggest you use) You basically want to give Parsley a method that will find the .errorBlock container based on the input field. It would look something like this:

    var parsleyConfig = {
        errorsContainer: function(pEle) {
            var $err = pEle.$element.siblings('.errorBlock');
            return $err;
        }
    }
    
    $('#yourFormID').parsley(parsleyConfig);
    

    And here's a live example.

    Note: using this method you can't use the parsley-validate attribute that Makrand suggests. Calling .parsley on your form does the same thing, except you can add your custom options to it. Also, you need to prefix all of your parsley attributes with data-, because they're data attributes (as of v2.0).

    0 讨论(0)
  • 2021-02-13 17:31

    try this:

    data-parsley-errors-container=".errorBlock"
    

    You can check this attribute in Parsley Documentation

    0 讨论(0)
  • 2021-02-13 17:32

    In reference to @ahmad hussain's answer you also need to put an attribute in your form:

    <form parsley-validate>
    
    0 讨论(0)
提交回复
热议问题