[ 7 posts ]

Roman Stachura

  • Username: stachrom
  • Joined: Wed Feb 10, 2010 12:48 am
  • Posts: 21
  • Twitter: stachrom
  • GitHub: stachrom
  • Gists: stachrom
  • IRC: stachrom
  • Offline
  • Profile

set a radio button checked in ChoiceField

Post Posted: Mon Jan 24, 2011 1:50 pm
+0-
How do i preset a radio button as checked?
Code:
    var f = new Y.Form({
        boundingBox: '#form',
        action : 'test.php',
        method : 'post',
        children : [
                  {name : 'Radio',  type   : 'ChoiceField',  label  : 'Radio: ',  multi : false,  choices : [
                     {label : 'Foo', value : 'foo'},
                     {label : 'Bar', value : 'bar'},
                     {label : 'Foo1', value : 'foo1'},
                     {label : 'Bar1', value : 'bar1'} ]
                  }
        ]
    });

Greg Hinch

YUI Contributor

  • Username: greghinch
  • Joined: Wed Jun 03, 2009 10:49 am
  • Posts: 73
  • Location: Fairfax, CA , USA
  • Twitter: greghinch
  • GitHub: ghinch
  • Gists: ghinch
  • IRC: gr-eg
  • Offline
  • Profile

Re: set a radio button checked in ChoiceField

Post Posted: Wed Jan 26, 2011 8:50 am
+0-
This was an oversight, I just committed a change to fix this. Now setting the "value" attribute of the field equal to one of the values for one of the choices will result in that being preselected. This change is only in Github right now, I'll request it be put up to the CDN and it should be there soon.

Roman Stachura

  • Username: stachrom
  • Joined: Wed Feb 10, 2010 12:48 am
  • Posts: 21
  • Twitter: stachrom
  • GitHub: stachrom
  • Gists: stachrom
  • IRC: stachrom
  • Offline
  • Profile
Tags:

Re: set a radio button checked in ChoiceField

Post Posted: Fri Jan 28, 2011 6:15 am
+0-
Nice, for the radiobutton it works well.

there is one case it might not work:

preslect for checkboxes: you may like to preslect 2 or more.

Code:
{
   name : 'checkbox',
   type : 'ChoiceField',
   label : 'checkbox'
   value :'foo, bar',
   multi: true,
   choices : [
                   {label : 'Foo', value : 'foo'},
                   {label : 'Bar', value : 'bar'}
]
}

Greg Hinch

YUI Contributor

  • Username: greghinch
  • Joined: Wed Jun 03, 2009 10:49 am
  • Posts: 73
  • Location: Fairfax, CA , USA
  • Twitter: greghinch
  • GitHub: ghinch
  • Gists: ghinch
  • IRC: gr-eg
  • Offline
  • Profile

Re: set a radio button checked in ChoiceField

Post Posted: Mon Feb 21, 2011 9:49 am
+0-
Sorry it took a little while, but I am just pushing a new version that should accept multiple values like you show here. It also should properly set the value as "foo,bar" when you check multiple now.

Richard Jones

  • Username: jonesr
  • Joined: Sat Jan 08, 2011 2:50 am
  • Posts: 10
  • Offline
  • Profile

Re: set a radio button checked in ChoiceField

Post Posted: Wed Mar 16, 2011 4:44 pm
+0-
I'm trying to set values on a ChoiceField after construction of the form with:
field.set("value",val);

However the value change is not being reflected in the UI like it is when the same code is run on a TextField. Is this a bug, or am I missing something?

Jin Joo

  • Username: jin
  • Joined: Wed Aug 04, 2010 11:03 pm
  • Posts: 4
  • Offline
  • Profile

Re: set a radio button checked in ChoiceField

Post Posted: Fri Oct 28, 2011 11:42 pm
+0-
I've found that in the current code I had to do the following to make the ui reflect my new value:
Code:
myChoiceField.set('value', 'myVal');
myChoiceField.syncUI();


I also have problems doing this when multi=true (set of checkboxes) that I outlined here; https://github.com/ghinch/yui3-gallery/issues/9

Richard Jones

  • Username: jonesr
  • Joined: Sat Jan 08, 2011 2:50 am
  • Posts: 10
  • Offline
  • Profile

Re: set a radio button checked in ChoiceField

Post Posted: Sat Oct 29, 2011 4:36 pm
+0-
Thanks Jin.
  [ 7 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum