Forums

Adding New Option in Select Options

codeslayer 20 Aug, 2011
Hi,

I would like to know if this possible in CF4.
Like in another form builder for joomla, if a select box (ex. Language)is displayed on the frontend form with the options "English", "Spanish" and "Italian" only.

[attachment=2]1.png[/attachment]

If the user want to add another language "Korean". He can update the existing options and add "Korean" language to be available.

[attachment=1]2.png[/attachment]

The option is saved into the database and now will be available whenever the drop down menu is used.

[attachment=0]3.png[/attachment]

This can be very useful in many cases where a user (or moderator) can update options.
GreyHead 20 Aug, 2011
Hi codeslayer,

The 'combo' box isn't built in to ChronoForms but it is possible to build one with a little code. If I remember correctly there is a Combo box in Joomla! HTML code somewhere as it is used in some of the admin dialogues.

Bob
codeslayer 20 Aug, 2011
Can you guide me a little because I am not fimiliar with Joomla code.
GreyHead 20 Aug, 2011
Hi codeslayer,

Try Googling 'Joomla! combobox'. The main docs are here but they don't tell you much.

Bob
codeslayer 20 Aug, 2011
These are way above my head.
I am considering my self as a beginner. So I'll stick to my goals with choronoforms. May be by the end of this project and untill I am fimiliar with more Joomla syntaxes, I'll try again in future.
Max_admin 20 Aug, 2011
Hi codeslayer,

Another solution is to have an "other" option in the dropdown box, when selected it enables a text box AFTER the dropdown but with a field name EXACTLY the SAME as the dropdown, so the text field is disabled by default, once "other" is selected its enabled, once another option is selected it gets disabled again, this will ensure that the value passed for that field name is either the dropdown value, or the text box value but only when other is selected, I wish that was clear๐Ÿ™‚

a code snippet for disable/enable:


//assuming the select box id is "my_select" and the text box id is "my_text", but both should have the same field name
window.addEvent('domready', function(){
	$('my_text').set('disabled', true);
	$('my_select').addEvent('change', function(){
		if($('my_select').get('value') == 'other'){
			$('my_text').set('disabled', false);
		}else{
			$('my_text').set('disabled', true);
		}
	});
});


Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
codeslayer 20 Aug, 2011
Hi Max,

Thanks for the reply.
It worked !๐Ÿ˜€
Nice tweak. Will come handy with my future forms.
GreyHead 21 Aug, 2011
Hi codeslayer,

Max's approach will work well - but note that it doesn't add the new option to the list to be displayed in the future (unless you add quite a lot more code in the background).

Bob
codeslayer 21 Aug, 2011
Hi GreyHead,

Yes you are right that its just another way to solve the problem. Its not a permanent solution.

In the ideal situation. We might need something like a new element type Database Driven Dropdown Menu. This dropdown menu should populates from the values stored in the database table for ex. cf_ChronoElements_Form1_Language. Once this DbDDdM is placed on the from, on its edit window there should be option to create new table which store Name and value to be displayed in the Dropdown menu. This dropdown menu should also be updatebale from the front end with ofcourse exclusive permisions to add new names and values to the database so that the new values will be stored for future use. I am not sure if I am supposed to refer Fabrik here which does exectly as above stated. (If refering other joomla form generator like Fabrik is prohibited on this board, please remove the name)

LOL ๐Ÿ˜€ I dream too much. I know there will be alot of coding behind this, But this element type will definately a very usefull feature.
GreyHead 21 Aug, 2011
Hi codeslayer,

Yes, I believe that is what the Joomla! combobox does - itg might even be that Fabrik uses the Joomla! code.

Bob
codeslayer 21 Aug, 2011
Hi Bob,

I have not seen and could not find anywhere what joomla box looks like and what it does. Googling joomla combobox returns JHtmlBehavior::combobox/1.6 and 11.1 Documentation but no examples.
Can you point out where I can see Joomla combobox example.

Thanks
GreyHead 22 Aug, 2011
Hi codeslayer,

The Module position box (here in Joomla! 1.5) is a combo box.

Bob
codeslayer 22 Aug, 2011
Thank you for reply Bob.

In this screenshot, the dropdown menu is getting its values from the xml file. Again it only read what options are given in xml file. So if you want to add more option in the list. You have to add required fields to the xml file to make them available. You cannot add fields on the form at runtime. So again I would insist you take a look at how fabrik's dropdown box element works.

Thanks again
Hassan
GreyHead 22 Aug, 2011
Hi Hassan,

I just added the xxxx in there before taking the screenshot. So you can add options at runtime.

Bob
codeslayer 23 Aug, 2011
Hi Bob,

You are right the value are storing in db and available if we need to reuse it when deseired.

Regards
Hassan
johanqnms 21 Jan, 2013
Greetings,

Would be good if Chronoforms implement the possibility to add new field to the Dropdown like Fabrik component.

This option is very important for some projects.

Thanks๐Ÿ™‚
GreyHead 21 Jan, 2013
Hi johanqnms,

I think most of the code is in this FAQ though you'd need to validate and save the new options to make them automatically add to the list.

Bob
This topic is locked and no more replies can be posted.