Adding Rule Validations for widgets in pure JS

Users
2016-05-04
2016-07-04
  • Shivali Agarwal

    Shivali Agarwal - 2016-05-04

    Hi, I am still learning metawidgets. I have a situation where I need to disable or enable 'href' and a 'button' based on data that is populated in a widget created using metawidgets. So, I already have an inspectionresultprocessor which reads a property file and renders the widgets native to Javascipt UI framework. I am unable to associate further rules that are dependent on the populated data. So, for example, if username is X, then enable edit else disable. Please help me with this.

    Thanks in advance.
    Shivali

     
  • Kennard Consulting

     
    • Shivali Agarwal

      Shivali Agarwal - 2016-05-13

      Thanks for the example. It really helped. I have a related question. In the example, the property used is disabledUnless. Is 'disabledUnless' a special attribute/property like 'hidden' or is it something that was just defined in the js file for the example. Also, where can we find the complete list of property attributes (like 'hidden') in the documentation?

      Thanks,
      Shivali

       
  • Kennard Consulting

    It was defined in the js file for the example. All the code you need is in the example. You can see it is injected by the Inspector, and handled by the WidgetProcessor (a few lines below).

     
  • Shivali Agarwal

    Shivali Agarwal - 2016-05-18

    I see. Thanks a lot for your prompt responses. It really helps a lot.
    I have couple of more queries:
    i) Is it possible to inspect two objects together and then buildwidgets.
    For example, in showDialog method in contacts.js in Addressbook example, the object is given in the path as mw.setAttribute( 'path', 'addressbook.current' ); Here, how do we add another object such that the widgets from first one are readonly while second one are editable?

    ii) How do we specify properties on nested attributes? For example, in the following JSON, if I have to hide ipAddress widget, how should I specify in JsonSchemaInspector?
    {
    "data":[ {
    "machines":{
    "ipAddress": "90.12.23.15",
    "shortName": "abc"
    },
    "timezone": "America/New_York"
    }]

    }
    I did try a few things but they did not seem to work...
    Thanks a ton!

     
  • Kennard Consulting

    1. The idea here is you would use multiple Metawidgets on a page, either side-by-side or embedded within each other. Metawidgets are very lightweight (they can all share the same config objects). You can use lots together.

    2. JsonSchemaInspector supports this automatically. It will be something like (note the items/properties convention, as defined by the JSON Schema specification):

    "properties": {
       "data": {
          "items": {
             "properties: {
                "ipAddress": {
                   hidden: true
                }
             }
          }
       }
    }
    
     
  • Shivali Agarwal

    Shivali Agarwal - 2016-05-19

    Okay. I understand. Thanks a lot.

     
  • Shivali Agarwal

    Shivali Agarwal - 2016-07-02

    Hi,
    What would be a good way of adding custom validations on inputs that are added in a form created using metawidgets for Javascript? For example, if I want to check if a number falls in range, or if an email id is in the correct format, how should I add these? Also, I have seen some plugins for JqueryValidator https://jqueryvalidation.org , how could we use such plugins for metawidgets?
    Thanks,
    Shivali

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks