Announcement Announcement Module
Collapse
No announcement yet.
Spring Js and custom dojo widgets Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Js and custom dojo widgets

    hello,

    Is there a way in

    Code:
    Spring.addDecoration(new Spring.ElementDecoration({
    elementId : "${def.code}",
    widgetType : "dijit.form.NumberTextBox",								widgetAttrs : {promptMessage: "Enter a number",
                         value:'10',
                         required: "true",
                         style:"width:150px;",
                         invalidMessage: "Invalid number"}
    }));
    to use custom widget types like for e.g. the OracleDateTextBox on the dojo site(http://dojotoolkit.org/book/dojo-boo...urrency-number)

    ~s.

  • #2
    Absolutely. You should be able to use any Dojo widget type that is available in your current environment.

    The specific case of using the example OracleDateTextBox is a little trickier, because the Spring.ElementDecoration assumes you need to have a dojo.require statement before constructing an instance of the widgetType. But there is an optional widgetModule parameter that is used when you need to require something other than the given widgetType.

    So in this specific case, the brute force way would be to put the custom widget declaration:

    Code:
    dojo.require("dijit.form.DateTextBox");
           
    dojo.declare("OracleDateTextBox",[dijit.form.DateTextBox], {
          serialize: function(d, options) {
             return dojo.date.locale.format(d, {selector:'date', datePattern:'dd-MMM-yyyy'}).toLowerCase();
           }
    });
    of the OracleDateTextBox in the <head> section of the page. Then the decoration could be something like:

    Code:
    Spring.addDecoration(new Spring.ElementDecoration({
    	elementId : "checkoutDate",
    	widgetType : "OracleDateTextBox",
            widgetModule : "dijit.form.DateTextBox",
    	widgetAttrs : { value : dojo.date.locale.parse(dojo.byId("checkoutDate").value, {selector : "date", datePattern : "yyyy-MM-dd"}), required : true }
    }));
    In this case the dojo.require of the widgetModule type would end up being a no-op since you already required "dijit.form.DateTextBox" in the <head>.

    The better way would be to package OracleDateTextBox into its own module (as the linked dojo docs suggest) so that it can be dojo.required without the additional widgetModule parameter in the decoration.

    Comment


    • #3
      Dojo Spring

      I am using date text box on my page.i am actually trying to populate a date field from the database if it exists show it in the datetextbox and provide the user an option to edit the field by providing a datetextbox.but when the page loads the field appears empty( If i right click and try to view the source of the page the datetextbox actually holds the value).if i refresh the page again i can see the date field value.Not sure what the problem is.Any help will be appreciated.my code looks something like this:

      <script type="text/javascript">
      dojo.require("dojo.parser");
      dojo.require("dijit.form.DateTextBox");
      dojo.declare("myDatetextBox",[dijit.form.DateTextBox], {
      serialize: function(d, options) {
      return dojo.date.locale.format(d, {selector:'date', datePattern:'dd-MMM-yyyy'}).toLowerCase();
      }
      });
      </script>
      </head>

      <form>
      <input dojoType="myDatetextBox" name="mydate" />
      //logic to get the value from database--using spring bind tags
      <input type="submit" value="go"/>
      </form>

      Comment

      Working...
      X