JavaCake
JavaCake

Reputation: 4115

Disabling inputFields via checkBox with Zend_Dojo_Form

I am expanding forms that are created with Zend_Dojo, for this i have a special task that i have hard time solving.

The form is for purchase and consist of two address groups: payerAddressGroup and deliveryAddressGroup.

These two groups are separated, so you can define two individual addresses. Although it occurs many times that the payerAddress is identical to the deliveryAddress.

So i wanted to resolve this task by adding a checkBox that could disable the deliveryAddressGroup, and by the value of the checkBox only use the payerAddress.

The form creation is made with extension of Zend_Dojo_Form.

I hope it makes sense!

Thanks.

I hope it makes sense?

Upvotes: 1

Views: 335

Answers (1)

Richard Ayotte
Richard Ayotte

Reputation: 5080

You can watch the 'checked' property.

dojo.ready(function() {
    dijit.byId('shipAsPayCheckBox').watch('checked', function(property, oldValue, newValue) {
        dojo.forEach(dijit.findWidgets(dojo.byId('fieldset-deliveryGroup')), function(w) {
            w.set('disabled', oldValue);
        });
    });
});

Your markup should look something like this.

<input id="shipAsPayCheckBox" name="shipAsPayCheckBox" dojoType="dijit.form.CheckBox" value="1" type="checkbox" /> 
<fieldset id="fieldset-deliveryGroup">
    <button dojoType="dijit.form.Button" type="button">Button</button>
    <label for="income1">
    U.S. Dollars
    </label>
    <input type="text" name="income1" id="income1" value="54775.53" dojoType="dijit.form.CurrencyTextBox" required="true" constraints="{fractional:true}" currency="USD" invalidMessage="Invalid amount.  Cents are required.">
</fieldset>

Upvotes: 1

Related Questions