Parsley.js - change error container

前端 未结 4 965
情歌与酒
情歌与酒 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: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).

提交回复
热议问题