Dojo Order method to keep count before actual value

Using Dojo 1.6.1.

Update: Here's a jsfiddle http://jsfiddle.net/E4EaM/1/

The form is created with some fields.

this.projectServiceidField = new dijit.form.TextBox({
    label: 'idField'
    , name: 'project_service_id'
    , required: true
    , type: 'hidden'
}).placeAt(this.domNode);

this.projectServiceEquipmentSourceAddress = new dijit.form.FilteringSelect({
    name: 'source_address_id'
    , required: true
    , store: model.CustomerAddressesPairsView
    , searchAttr: "name"
    , style: "width: 40ex;"
});

      

The app should be notified when all the widget values ​​are set. To do this, a Deferred object is created with a Stateful clock on the Widget property. Deferred objects are all placed in the Deferred list. After the widget value has been initially set, the clock is removed and the Deferred object is resolved.

//loop 
w.deferred = new dojo.Deferred();
da.push(w.deferred);

// Watch the widget value
w.initWatch = w.watch('value', function(property, oldValue, newValue) {
    w.initWatch.unwatch();
    console.debug(w.name, 'property:', property, 'oldValue:', oldValue,'newValue:', newValue,'w.get(\'value\'):', w.get('value'));
    w.deferred.resolve();
});

// Set the widget value
w.set('value', value);

//endloop

var dl = new dojo.DeferredList(da);

      

When DeferredList is enabled, all widget values ​​must be set.

dl.then(
    function() {
        dojo.forEach(da, function(d) {
            console.debug(Date.now(), d);
        })

        console.debug(Date.now(), dl, 'DeferredList resolved -------->', form.getValues());
        console.debug(form.getValues());
    }
);

      

But it doesn't work as expected. In particular, the fields that handle xhr. Here are the values ​​generated in value change events.

project_service_id property: value oldValue: newValue: 1025 w.get ('value'): 1025

source_address_id property: value oldValue: newValue: 59 w.get ('value'):

source_address_id should have been 59, but when I w.get ('value') it is not equal to newValue. Shouldn't they be?

How to determine when a widget value is set? Why not value == w.get ('value') right after w.set ('value', value)?

If w.set ('value', value) doesn't really set a value, shouldn't it return deferred ones?

Shouldn't you just watch the fire after the value has been set?

Dojo Versions:

Crash in Dojo 1.6.1. The clock doesn't always fire, and w.get ('value')! = NewValue when it does.

Crash less than Dojo 1.7.2. The clock still doesn't always fire, but at least w.get ('value') == newValue.

+3


source to share


1 answer


after some discussion with richard on irc, we were able to figure out that there is some nuance between dojox.data.QueryReadStore

and dijit.form.FilteringSelect

that prevents the callback from being triggered "value"

if the store has not yet executed fetch

. the working solution was to do first fetch

and then create the widget in the callback onComplete

- see http://jsfiddle.net/neonstalwart/dEC7M/

relevant part



customerAddressesPairsView.fetch({
    onComplete: function() {
        var w = new dijit.form.FilteringSelect({
            name: 'source_address_id',
            required: true,
            store: customerAddressesPairsView,
            searchAttr: "name",
            style: "width: 40ex;"
        }, 'sourceAddress');

        var handle = w.watch(function(property, oldValue, newValue) {
            console.log(property, oldValue, newValue);
        });

        w.set("value", value1);
        console.debug('Value set to ' + value1);
        console.debug('Immediate get returns:', w.get('value'));
        console.debug('Direct access returns: ' + w.value);
    }
});

      

+4


source







All Articles