|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
bobthecow Smarty n00b
Joined: 19 Jan 2009 Posts: 2
|
Posted: Mon Jan 19, 2009 8:04 pm Post subject: 'disabled' support for {html_options} |
|
|
I found myself in need of 'disabled' support for html options today, so I made a quick update to the Smarty {html_options} plugin. To use it, simply pass a 'disabled' array, much like the 'selected' param. It would be great to see this in the next version of Smarty as well.
Updated plugin (there's a download and a patch there).
Last edited by bobthecow on Mon Jan 19, 2009 8:06 pm; edited 1 time in total |
|
Back to top |
|
mitchenall Smarty Pro
Joined: 27 Feb 2004 Posts: 107 Location: London, UK
|
Posted: Tue Jan 20, 2009 2:23 am Post subject: |
|
|
So, you output an input field in a disabled state? Not use javascript to disable it? So, anyone without javascript cannot enable it? So, why is it an input element, if it can't be input into? _________________ Mark Mitchenall |
|
Back to top |
|
bobthecow Smarty n00b
Joined: 19 Jan 2009 Posts: 2
|
Posted: Tue Jan 20, 2009 3:04 am Post subject: |
|
|
This is for disabling individual options in a select list. It's not for disabling an entire input field. Here's a possible use case:
Say you have an e-commerce store that targets the Greater NY Metropolitan area. You want the state picker to show those states first, but it's awkward if you jump right into Alabama and Alaska. So you add a separator, say, a set of hyphens.
Unfortunately, this set of hyphens would be selectable, which is confusing, to say the least. So you disable the "---" option, keeping anyone from accidentally choosing it. That's what this plugin update allows.
Code: | $smarty->assign('options', $states);
$smarty->assign('disabled', array('null')); |
Code: | {html_options options=$options disabled=$disabled} |
Code: | <select>
<option value="ny">New York</option>
<option value="nj">New Jersey</option>
<option value="ct">Connecticut</option>
<option value="pa">Pennsylvania</option>
<option value="null" disabled="disabled">---</option>
<option value="al">Alabama</option>
...
</select> |
Last edited by bobthecow on Tue Jan 20, 2009 3:04 am; edited 1 time in total |
|
Back to top |
|
ungalcrys Smarty n00b
Joined: 01 Nov 2013 Posts: 1
|
Posted: Fri Nov 01, 2013 4:09 pm Post subject: |
|
|
you must add strict strict attribute. check the sample below:
Code: | {html_options options=$options disabled=(if condition here) strict='1'} |
worked for me. it enabled/disabled the select element if the condifion result was false/true. hope it works on your system also.
PS: check http://www.smarty.net/docs/en/language.function.html.options.tpl |
|
Back to top |
|
freshdouble Smarty n00b
Joined: 26 Aug 2014 Posts: 1
|
Posted: Tue Aug 26, 2014 10:50 am Post subject: |
|
|
I know this is an old thread but for those who search for an answer i will post mine
I added the code as an issue on google-code, i dont know if its realy an issue or not, but i would be glad if this option would be in an future release of smarty
https://code.google.com/p/smarty-php/issues/detail?id=198 |
|
Back to top |
|
|
|
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 You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|