FeedbackPanel stylize/change message - wicket

How to stylize my Feedback message? Now it's like a normal html list element.
How to change my Feedback messages for validators like email validator?
I know that I can change the .setRequired() message with a property file and the following code:
Required=Provide a ${label} or else...
form.userId.Required=You have to provide a name

You'd need to subclass FeedbackPanel (or reimplement it on your own) and override the newMessageDisplayComponent(String id, FeedbackMessage message) method to return any component of your liking. See JavaDoc of FeedbackPanel
As for custom validator messages: When calling error in your custom validator you can supply a resourceKey by which the application tries to find your error message. As above: JavaDoc is your friend.

Related

Custom Form Layout Validation

I want to have my own validation flow, with custom layout and message.
By default, the validation from the form builder put all the error message beside the input field. And it will validate all fields at once after submit.
I want to validate field by field after submitting, and error message is displayed in the same place for all the input fields (beside the submit button/on top of the form).
Currently I'm trying custom form layout with "ASCX" type. Is it possible to do all the validation in the back-end code ".cs"?
Or I must inject java script at the custom form layout design in source mode?
Or there is any better way to do it?
In HTML layout type you can place validation macros anywhere you need -> $$validation:FirstName$$
You can also specify a validation that executes without submitting the form - example -> http://devnet.kentico.com/articles/tweaking-kentico-(2)-unique-fields
Anyway, with the validation macro above you can move the error message wherever you want.
In your online form, go to Layout and enter your layout markup manually using HTML and the macros for form field values, labels and validation. There you can specify where all your form elements will go on the form, even the button.
If you want to have custom CS for your validation of that form, you're better off creating a custom event handler for the form before insert. See documentation below:
Custom event handler
Form Event handler
using CMS;
using CMS.DataEngine;
using CMS.OnlineForms;
using CMS.Helpers;
// Registers the custom module into the system
[assembly: RegisterModule(typeof(CustomFormModule))]
public class CustomFormModule : Module
{
// Module class constructor, the system registers the module under the name "CustomForms"
public CustomFormModule()
: base("CustomForms")
{
}
// Contains initialization code that is executed when the application starts
protected override void OnInit()
{
base.OnInit();
// Assigns a handler to the Insert.After event
// This event occurs after the creation of every new form submission
BizFormItemEvents.Insert.After += Insert_After;
}
private void Insert_After(object sender, CMS.OnlineForms.BizFormItemEventArgs e)
{
if (e.Item.TypeInfo.ObjectType.ToLower().Contains("bizform.codename"))
{
//do some work or form validation
}
}
}

Wicket 1.5 - EmailTextField: accept "plus" symbol

I'm using a EmailTextField in a wicket 1.5 app in order to log users. According to GMail alias, a + symbol may be present in email but wicket doesn't allow it. Is there a way to accept extra symbol in the validator?
You have to write your own validator:
public class GMailAddressValidator extends PatternValidator {
public GMailAddressValidator() {
super("^[_A-Za-z0-9-+]+(\\.[_A-Za-z0-9-+]+)*#[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z]{2,}){1}$)",
Pattern.CASE_INSENSITIVE);
}
}
Here I just add two pluses to original Wicket regexp for validating e-mails (tried to highlight pluses in bold):
^[_A-Za-z0-9-+]+(\\.[_A-Za-z0-9-+]+)*#[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z]{2,}){1}$)
After that you could use simple TextField with your validator instead of EmailTextField. Like that:
new TextField<String>("email").add(new GMailAddressValidator())
I think you will have to override the HTML5 validation like this: Override html5 validation, the component only sets the input type to email, i dont think it adds any wicket validation. If you dont want to add the js override, the best thing todo would be to create your own validator for a wicket TextField.

Wicket: How to post a Feedback Message from within the FeedbackPanel

I have a form with ComponentFeedbackPanels. I have implemented a Filter, that removes the FeedbackMessage shown in the ComponentFeedbackPanels (I have adapted this solution) from the top-of-the-page FeedbackPanel.
Now I would like to add a Feedback Message to the top level to remind the users to read CompnoentFeedback Messages that are displayed next to the form fields.
I don't know how to add such a message. Calling error() from within that filter or FeedbackPanel or the parent page when already filtering does not add anything to the current FeedbackPanel...
To add a top-level message, use Session.get().error(message).

How to show just one (e.g. the first) error message to a form field with Zend framework where validation has failed?

Is there any way to do that with a decorator or do I need to dig deeper into ZF?
If you have multiple validators attached to one form element and want only the first error message to pop up, you can set breakChainOnFailure option to TRUE for each validator. In this case, if one of the validators fails, all the subsequent validators are skipped.
$element->addValidator(
new Zend_Validate_StringLength(array('min' => 6, 'max' => 12)),
true)
->addValidator(new Zend_Validate_Alnum());
if $foo is in an instance of Zend_Form and there is an form element username inside this form then
$foo->username->getMessages() ; will return array of errors messages to show only one you simply need to do array_pop($foo->username->getMessages()); . Basically zend decorators uses error view helper to display the messages . You need to extend the default decorator and remove the view helper simply by echo
There are many ways you can do this. My personal favorite is to extend the validator you want to use to only return one custom message. For the email validator this is especially helpful since it shows some crazy error messages that you may not want to show anyway. You can see this method here: http://clintberry.com/2010/07/zend-form-email-validator-customizing-error-messages/

triggering invalid message with zend_dojo elements on post fail

I am having a few issues with a Zend_Form that I have which uses Dojo elements to handle user validation.
The scenario is when are user fills in the form the dojo elements ensure the formatting is correct. On post of the form if there is an error such as the email address already existing in the database, my code throw an exception that I catch, I want to then use the dojo validation to display the error rather than having error messages at the top or bottom of the form.
I've tried the following:
catch(Exception $e){
$signupForm->populate($formData);
$signupForm->getElement('email')->setInvalidMessage('email addresss already exists');
$this->view-form = $signupForm;
}
This redisplays the form but does not highlight the dojo element to show what element is failing. How can this be done or am I going to have to display the error messages somewhere on the form in an list?
Any help would be gratefully received.
Did you take a look at Zend_Dojo_Form?