Issue setting value in Dijit Select

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue setting value in Dijit Select

Harry Devine
I have a Dijit Select control that I'm trying to set the initial value
for.  No matter what value I get from the database, I always get No
displayed.  The value from the database will be either Yes or No.  
Here's how I'm trying to set the control:

           /* Set the Alumni designation */
           if (!registry.byId("editAlumni")) {
console.log("Initial - Setting editAlumni to ", data[0].alumni);
             editAlumni = new Select({
               id: "editAlumni",
               name: "editAlumni",
               value: data[0].alumni,
               store: mod.alumniStore,
               labelAttr: "alumni",
               sortByLabel: false,
               searchAttr: "alumni",
               style: "width: 125px;"
             }, "editAlumni");
console.log("Initial - editAlumni value ", editAlumni.get("value"));
           }
           else {
           editAlumni.reset();
console.log("Secondary - Setting editAlumni to ", data[0].alumni);
             editAlumni.set("value", data[0].alumni);
console.log("Secondary - editAlumni value ", editAlumni.get("value"));
             editAlumni.set("store", mod.alumniStore);
           }

The mod.alumniStore store is configured as follows:

{"identifier": "alumni",
   "items": [
             {"id":1,"alumni":"No"},
             {"id":2,"alumni":"Yes"}
   ]
}

Any ideas on why it always shows the No value?  In my console, I see
that when the value is Yes, data[0].alumni above will show Yes.  But the
control ALWAYS shows No.

Thanks,

Harry

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Issue setting value in Dijit Select

Harry Devine
I have created a JSFiddle showing my issue here:
https://jsfiddle.net/n7vwokab/5/

Thanks,

Harry

On 8/19/2017 6:10 PM, Harry Devine wrote:

> I have a Dijit Select control that I'm trying to set the initial value
> for.  No matter what value I get from the database, I always get No
> displayed.  The value from the database will be either Yes or No.
> Here's how I'm trying to set the control:
>
>             /* Set the Alumni designation */
>             if (!registry.byId("editAlumni")) {
> console.log("Initial - Setting editAlumni to ", data[0].alumni);
>               editAlumni = new Select({
>                 id: "editAlumni",
>                 name: "editAlumni",
>                 value: data[0].alumni,
>                 store: mod.alumniStore,
>                 labelAttr: "alumni",
>                 sortByLabel: false,
>                 searchAttr: "alumni",
>                 style: "width: 125px;"
>               }, "editAlumni");
> console.log("Initial - editAlumni value ", editAlumni.get("value"));
>             }
>             else {
>             editAlumni.reset();
> console.log("Secondary - Setting editAlumni to ", data[0].alumni);
>               editAlumni.set("value", data[0].alumni);
> console.log("Secondary - editAlumni value ", editAlumni.get("value"));
>               editAlumni.set("store", mod.alumniStore);
>             }
>
> The mod.alumniStore store is configured as follows:
>
> {"identifier": "alumni",
>     "items": [
>               {"id":1,"alumni":"No"},
>               {"id":2,"alumni":"Yes"}
>     ]
> }
>
> Any ideas on why it always shows the No value?  In my console, I see
> that when the value is Yes, data[0].alumni above will show Yes.  But the
> control ALWAYS shows No.
>
> Thanks,
>
> Harry
>

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Issue setting value in Dijit Select

gumbawumba
In reply to this post by Harry Devine
Hi, Please see this link.
https://dojotoolkit.org/documentation/tutorials/1.10/selects_using_stores/

Using Stores with dijit/form/Select
We noted earlier that when using stores, dijit/form/Select and dijit/form/FilteringSelect associate their value with the identity of the currently-selected item. However, dijit/form/Select possesses an important limitation: it is implemented in such a way that it does not handle non-string item identities well. Particularly, setting the current value of the widget programmatically via select.set("value", id) will not work with non-string (e.g. numeric) identities.

Here is some modified fiddle code that works.

require(["dijit/form/Select", "dojo/store/Memory", "dijit/registry"
], function(Select, Memory, registry){
  var someData = [
        {id:"No", name:"Not Alumni"},
        {id:"Yes", name:"Yes Alumni"}
    ];
  alumniStore = new Memory({data: someData});

  /* Set the Alumni designation */
  if (!registry.byId("editAlumni")) {
    editAlumni = new Select({
      id: "editAlumni",
      name: "editAlumni",
      value: "Yes",      
      store: alumniStore,
      labelAttr: "name",
      sortByLabel: false,
      searchAttr: "name",
      style: "width: 125px;"
    }, "editAlumni");    
  }
  //editAlumni.set("value","No");
});