Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-771

When using a validator on a form, support the ability to retrieve messages individually

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.0.0
    • Component/s: Databind 2
    • Labels:

      Description

      Problem Statement

      At the moment you can have a validator on a form, for example:

      <groupbox form="@id('event') @validator('org.zkoss.todo.event.EventValidator')">
      

      However, when you do this there is no way to retrieve messages individually, so if you have a form you cannot place errors next to the respective component. This is the most common use case on forms, so in my opinion is essential.

      Possible solution

      When adding the invalid message like this this.addInvalidMessage(ctx, "age must be over 1"); we have an additional argument for the key:

      this.addInvalidMessage(ctx, "key", "message");
      

      We can then therefore retrieve the error message next to our respective component, for example say we want to validate the age in an intbox.

      this.addInvalidMessage(ctx, "age", "age must be > 1");
      

      Then in the zul file:

      <textbox id="txtAge" value="0" />
      <label value="@load(frm.validationmessage['age'])" visible="@load(not empty frm.validationmessages['age'])" />
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            tmillsclare tmillsclare
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: