mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
ENHANCEMENT clientside validation messages sourced from customisable serverside code. Several small bugfixes also
This commit is contained in:
parent
b1bc0c713b
commit
ca638e367a
@ -242,13 +242,25 @@ class CommentingController extends Controller {
|
|||||||
|
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
$fields = new FieldList(
|
$fields = new FieldList(
|
||||||
new TextField("Name", _t('CommentInterface.YOURNAME', 'Your name')),
|
TextField::create("Name", _t('CommentInterface.YOURNAME', 'Your name'))
|
||||||
new EmailField("Email", _t('CommentingController.EMAILADDRESS', "Your email address (will not be published)")),
|
->setCustomValidationMessage(_t('CommentInterface.YOURNAME_MESSAGE_REQUIRED', 'Please enter your name'))
|
||||||
new TextField("URL", _t('CommentingController.WEBSITEURL', "Your website URL")),
|
->setAttribute('data-message-required', _t('CommentInterface.YOURNAME_MESSAGE_REQUIRED', 'Please enter your name')),
|
||||||
new TextareaField("Comment", _t('CommentingController.COMMENTS', "Comments")),
|
|
||||||
new HiddenField("ParentID"),
|
EmailField::create("Email", _t('CommentingController.EMAILADDRESS', "Your email address (will not be published)"))
|
||||||
new HiddenField("ReturnURL"),
|
->setCustomValidationMessage(_t('CommentInterface.EMAILADDRESS_MESSAGE_REQUIRED', 'Please enter your email address'))
|
||||||
new HiddenField("BaseClass")
|
->setAttribute('data-message-required', _t('CommentInterface.EMAILADDRESS_MESSAGE_REQUIRED', 'Please enter your email address'))
|
||||||
|
->setAttribute('data-message-email', _t('CommentInterface.EMAILADDRESS_MESSAGE_EMAIL', 'Please enter a valid email address')),
|
||||||
|
|
||||||
|
TextField::create("URL", _t('CommentingController.WEBSITEURL', "Your website URL"))
|
||||||
|
->setAttribute('data-message-url', _t('CommentInterface.COMMENT_MESSAGE_URL', 'Please enter a valid URL')),
|
||||||
|
|
||||||
|
TextareaField::create("Comment", _t('CommentingController.COMMENTS', "Comments"))
|
||||||
|
->setCustomValidationMessage(_t('CommentInterface.COMMENT_MESSAGE_REQUIRED', 'Please enter your comment'))
|
||||||
|
->setAttribute('data-message-required', _t('CommentInterface.COMMENT_MESSAGE_REQUIRED', 'Please enter your comment')),
|
||||||
|
|
||||||
|
HiddenField::create("ParentID"),
|
||||||
|
HiddenField::create("ReturnURL"),
|
||||||
|
HiddenField::create("BaseClass")
|
||||||
);
|
);
|
||||||
|
|
||||||
// save actions
|
// save actions
|
||||||
|
@ -97,7 +97,8 @@ class CommentsExtension extends DataExtension {
|
|||||||
* @see docs/en/Extending
|
* @see docs/en/Extending
|
||||||
*/
|
*/
|
||||||
public function CommentsForm() {
|
public function CommentsForm() {
|
||||||
if (Commenting::has_commenting($this->owner->ClassName) && Commenting::get_config_value($this->owner->ClassName, 'use_ajax_commenting')) {
|
if (Commenting::has_commenting($this->ownerBaseClass) && Commenting::get_config_value($this->ownerBaseClass, 'use_ajax_commenting')) {
|
||||||
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
|
||||||
Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/lib/jquery.form.js');
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/lib/jquery.form.js');
|
||||||
Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/jquery.validate.pack.js');
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/jquery.validate.pack.js');
|
||||||
Requirements::javascript('comments/javascript/CommentsInterface.js');
|
Requirements::javascript('comments/javascript/CommentsInterface.js');
|
||||||
|
@ -22,6 +22,12 @@
|
|||||||
}, 200);
|
}, 200);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
showErrors: function(errorMap, errorList) {
|
||||||
|
this.defaultShowErrors();
|
||||||
|
// hack to add the extra classes we need to the validation message elements
|
||||||
|
form.find('span.error').addClass('message required');
|
||||||
|
},
|
||||||
|
|
||||||
errorElement: "span",
|
errorElement: "span",
|
||||||
errorClass: "error",
|
errorClass: "error",
|
||||||
|
|
||||||
@ -42,17 +48,17 @@
|
|||||||
},
|
},
|
||||||
messages: {
|
messages: {
|
||||||
Name : {
|
Name : {
|
||||||
required : 'Plaese enter your name'
|
required : form.find('[name="Name"]').data('message-required')
|
||||||
},
|
},
|
||||||
Email : {
|
Email : {
|
||||||
required : 'Plaese enter your email address',
|
required : form.find('[name="Email"]').data('message-required'),
|
||||||
email : 'Plaese enter a valid email address'
|
email : form.find('[name="Email"]').data('message-email')
|
||||||
},
|
},
|
||||||
Comment: {
|
Comment: {
|
||||||
required : 'Plaese enter your comment'
|
required : form.find('[name="Comment"]').data('message-required')
|
||||||
},
|
},
|
||||||
URL: {
|
URL: {
|
||||||
url : 'Please enter a valid URL'
|
url : form.find('[name="Comment"]').data('message-url')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -64,9 +70,8 @@
|
|||||||
*/
|
*/
|
||||||
form.submit(function (e) {
|
form.submit(function (e) {
|
||||||
|
|
||||||
// trigger validation, if there are errors add the error classes to the elements
|
// trigger validation
|
||||||
if(!form.validate().valid()){
|
if(!form.validate().valid()){
|
||||||
form.find('span.error').addClass('message required');
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,11 +94,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
commentsList.prepend(newComment.fadeIn());
|
commentsList.prepend(newComment.fadeIn());
|
||||||
|
|
||||||
$(this).resetForm();
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(this).resetForm();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user