Hi,
I think html-template really needs a templ_equal tag. I am trying to pre-select an option inside a select tag, based on parameters passed. Since the option tags are also being generated through a loop, I think there is no way I can do this unless I can have some comparison mechanism within the template. Kindly correct me if I'm wrong.
Thanks, Vamsee.
On Tue, 26 Dec 2006 03:50:03 +0530, Vamsee Kanakala vamlists@gmail.com wrote:
I think html-template really needs a templ_equal tag. I am trying to pre-select an option inside a select tag, based on parameters passed. Since the option tags are also being generated through a loop, I think there is no way I can do this unless I can have some comparison mechanism within the template. Kindly correct me if I'm wrong.
Could you provide an example of what you're trying to do?
Thanks, Edi.
Edi Weitz wrote:
Could you provide an example of what you're trying to do?
I have something like this, and the <option> tag needs to be selected when id matches the value of the parameter called location-id.
<p><label for="location-id">Location: </label> <select id="location-id" name="location-id"> <option value="">Choose a location</option> <!-- tmpl_loop rows --> <!-- tmpl_loop cols --> <option value="<!-- tmpl_var id -->"> <!-- tmpl_var name --></option> <!-- /tmpl_loop --> <!-- /tmpl_loop --> </select></p>
So I followed Igor's advice (thank you!) and changed the <option> tag above to this:
<option <!-- tmpl_var selected --> value="<!-- tmpl_var id -->"> <!-- tmpl_var name --></option>
Supported by this code:
(rows (loop for locationl in locations collect (list :cols (loop for location in locationl if (and (required-exist-p location-id) (equal (parse-integer location-id :junk-allowed t) (id location))) collect (list :id (id location) :name (name location) :selected "selected") else collect (list :id (id location) :name (name location)))))
It's working now. Do let me know if there are better ways to achieve this.
Vamsee.
On Tue, 26 Dec 2006 12:52:11 +0530, Vamsee Kanakala vamlists@gmail.com wrote:
I have something like this, and the <option> tag needs to be selected when id matches the value of the parameter called location-id.
<p><label for="location-id">Location: </label> <select id="location-id" name="location-id"> <option value="">Choose a location</option> <!-- tmpl_loop rows --> <!-- tmpl_loop cols --> <option value="<!-- tmpl_var id -->"> <!-- tmpl_var name --></option> <!-- /tmpl_loop --> <!-- /tmpl_loop --> </select></p>
So I followed Igor's advice (thank you!) and changed the <option> tag above to this:
<option <!-- tmpl_var selected --> value="<!-- tmpl_var id -->"> <!-- tmpl_var name --></option>
Supported by this code:
(rows (loop for locationl in locations collect (list :cols (loop for location in locationl if (and (required-exist-p location-id) (equal (parse-integer location-id :junk-allowed t) (id location))) collect (list :id (id location) :name (name location) :selected "selected") else collect (list :id (id location) :name (name location)))))
It's working now. Do let me know if there are better ways to achieve this.
That's fine. I'd probably do it a little bit different (see below, untested), but that's just a matter of taste:
<option <!-- tmpl_if selected -->selected <!-- /tmpl_if -->value="<!-- tmpl_var id -->"><!-- tmpl_var name --></option>
(loop for location in locationl collect (list :id (id location) :name (name location) :selected (and (required-exist-p location-id) (equal (parse-integer location-id :junk-allowed t) (id location)))))
On Tue, 26 Dec, 2006 at 03:50:03 +0530, Vamsee Kanakala wrote:
I think html-template really needs a templ_equal tag. I am trying to pre-select an option inside a select tag, based on parameters passed. Since the option tags are also being generated through a loop, I think there is no way I can do this unless I can have some comparison mechanism within the template. Kindly correct me if I'm wrong.
You can use parameters passed while generating data to fill the template. And set some variable to T at some particular loop step. That variable will be NIL at all other steps.
Then in the template use <tmpl_if> to emit "selected" inside <option>s.
In this way your template and data are still completely separate. It is GOOD THING. But with any kind of <tmpl_equal> they will not.
-- Registered Linux User #124759
html-template-devel@common-lisp.net