Getting Default Checked Checkbox in CQ5

前端 未结 3 1862
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 04:36

I am trying to have a default checked checkbox on a component dialog when editing. Here are the properties on the field:

jcr:primaryType: widget
checked: tr         


        
相关标签:
3条回答
  • 2020-12-31 04:54

    To set checkbox with a default value of checked and save the property as a Boolean property type in the JCR (rather than a String), use the following Classic UI settings:

    <myCheckbox
        jcr:primaryType="cq:Widget"
        fieldLabel="My Checkbox"
        name="./myCheckbox"
        value="true"
        defaultValue="true"
        checkboxBoolTypeHint="{Boolean}true"
        type="checkbox"
        xtype="selection"/>
    

    Or use the following settings in the Granite Touch UI:

    <myCheckbox
        jcr:primaryType="nt:unstructured"
        sling:resourceType="granite/ui/components/foundation/form/checkbox"
        text="My Checkbox"
        name="./myCheckbox"
        value="true"
        checked="true"/>
    <myCheckboxType
        jcr:primaryType="nt:unstructured"
        sling:resourceType="granite/ui/components/foundation/form/hidden"
        name="./myCheckbox@TypeHint"
        value="Boolean"/>
    

    There's a detailed writeup and demo at http://www.nateyolles.com/blog/2015/11/aem-checkboxes-using-sling-post-servlet.

    0 讨论(0)
  • 2020-12-31 04:55

    To have this saved as a Boolean...

    <nodeName
    jcr:primaryType="cq:Widget" 
    fieldLabel="check this nodename" 
    name="./nodeName" 
    defaultValue="{Boolean}false" 
    type="checkbox"
    xtype="selection" />
    
    <nodeNameHint
      jcr:primaryType="cq:Widget"
      ignoreData="{Boolean}true"
      name="./nodeName@TypeHint"
      value="Boolean"
      xtype="hidden"/>
    
    0 讨论(0)
  • 2020-12-31 05:03

    Yes, it looks like the documentation is a little wonky. I did some experimenting, and this combination of properties works for me:

    defaultValue (String) true
    fieldLabel (String) Foo Mode
    inputValue (String) false
    jcr:primaryType (Name) cq:Widget
    name (String) ./foomode
    type (String) checkbox
    xtype (String) selection
    

    The defaultValue property appears to be the key.

    You do have cq:Widget for your primary type, not widget, do you not?

    0 讨论(0)
提交回复
热议问题