Dropdown field in form

281 views
Skip to first unread message

Tommaso Allevi

unread,
Oct 30, 2012, 1:28:11 PM10/30/12
to agile-too...@googlegroups.com
Hi!
I'd like add a dropdown to a field without using model. to do this, 
$f = $this->add("Form");
$f->addField('dropdown', 'Hello!')->setValueList(array('bla1'=>'bla1', 'bla2'=>'bla2'));
When i set default value through all possible methods (Form_Field_ValueList::setEmptyText, Form_Field_Dropdown::emptyValue), the default value isn't set.
To set the default value i do this:
$f->addField('dropdown', 'Hello!')->setValueList(array('' => 'Default Value!', 'bla1'=>'bla1', 'bla2'=>'bla2'));
I'm asking to perform this...

PS: using models the correct way works fine!

Tommaso Allevi

unread,
Oct 30, 2012, 1:29:16 PM10/30/12
to agile-too...@googlegroups.com
I'm using 4.2.1
Message has been deleted

Tommaso Allevi

unread,
Oct 30, 2012, 1:48:18 PM10/30/12
to agile-too...@googlegroups.com
I have not found a way to set a field as mandatory.
I'using 
$f->addField('dropdown', 'Type')->setValueList(array(''=>'Choose type...', 'type1'=>'type1', 'type2'=>'type2'))->emptyValue('')->setEmptyText('Choose page type...')->setMandatory();

But doesn't work

Imants Horsts

unread,
Oct 30, 2012, 2:37:43 PM10/30/12
to agile-too...@googlegroups.com
Ok, this was really a bug and I have provided a patch for it here: https://github.com/atk4/atk4/pull/148
Let's wait while Romans accept that.

You can do on your page like then (after patch will be accepted):

$f = $this->add("Form");
$d1 = $f->addField('dropdown','Hello!')->setEmptyText('Nothing here...')->setValueList(array('b1'=>'bla1', '2'=>'bla2', 3=>'bla3'));

emptyValue() method will be removed completely because it's not implemented anyway and have no use. It was something obsolete I guess.

Gowrav Vishwakarma

unread,
Oct 30, 2012, 11:43:50 PM10/30/12
to agile-too...@googlegroups.com
Have you tested it with setNotNull or validateNotNull also if form is displaying proper error message on the array populated dropdown or not ..

--
 
 



--
Regards

Gowrav Vishwakarma
Man of Affairs, Digital Vish, Xavoc International
http://www.digitlavish.com : +91 9783807100
http://www.xavoc.com

--------------------------------------------------------------------
Never Never Never Never Never Never Never Never Never Never Never Never Never Never Never  GIVE UP

Imants Horsts

unread,
Oct 31, 2012, 6:10:34 AM10/31/12
to agile-too...@googlegroups.com
Yeah, just tested. It works with validateNotNull too. You get error message in form.
Only thing you shouldn't do is change $empty_value in ValueList class. It should always be "" (empty string).

$f = $this->add("Form");
$f->addField('dropdown','hello','Hello!')
->setEmptyText('Nothing here');
->setValueList(array('b1'=>'bla1', '2'=>'bla2', 3=>'bla3'));
->validateNotNULL('Value required');

$f->addSubmit();
if($f->isSubmitted()) {var_dump($_POST);}

Imants Horsts

unread,
Oct 31, 2012, 6:14:35 AM10/31/12
to agile-too...@googlegroups.com
This is correct test case (semicolons removed):
$f = $this->add("Form");
$f->addField('dropdown','hello','Hello!')
->setEmptyText('Nothing here')
->setValueList(array('b1'=>'bla1', '2'=>'bla2', 3=>'bla3'))
->validateNotNULL('Value required');

$f->addSubmit();
if($f->isSubmitted()) {var_dump($_POST);}


Tommaso Allevi

unread,
Oct 31, 2012, 7:23:29 AM10/31/12
to agile-too...@googlegroups.com
This code doesn't work correctly.
$f = $this->add("Form");

$f
->addField('dropdown', 'Type')->setEmptyText("Choose page type...")->setValueList(array('terms'=>'terms', 'policy'=>'policy'))->validateNotNull("Mandatory field");
On submit, the form doesn't check the property and the emptyText isn't shwon...

Imants Horsts

unread,
Oct 31, 2012, 8:11:45 AM10/31/12
to agile-too...@googlegroups.com
As I said before:
Ok, this was really a bug and I have provided a patch for it here: https://github.com/atk4/atk4/pull/148
Let's wait while Romans accept that.

You have to wait a bit while Romans will accept my fix (above) and then test.

Imants Horsts

unread,
Oct 31, 2012, 8:18:05 AM10/31/12
to agile-too...@googlegroups.com
You can check now. Romans just accepted my patch.
Just download newest atk4 source from atk4 master branch.

Tommaso Allevi

unread,
Nov 13, 2012, 12:20:15 PM11/13/12
to agile-too...@googlegroups.com
Hi!
i've found a little problem with setEMptyText: when i add the emtpy text,  the inserted  text is append to value_list.
I suggest to use array_merge at line 45 of Form_Field_ValueList.
For example
$this->value_list=array_merge(array($this->empty_value, $this->empty_text), $this->value_list);

Imants Horsts

unread,
Nov 13, 2012, 2:08:14 PM11/13/12
to agile-too...@googlegroups.com
It's because you want this empty value to be first in a list?
Reply all
Reply to author
Forward
0 new messages