Set check box as checked

15 views
Skip to first unread message

Chadly

unread,
Aug 4, 2008, 2:37:19 PM8/4/08
to Spark View Engine Dev
What is the easiest way to set a checkbox as checked based upon some
condition? I have tried this:

<macro name="Checked">
<if condition="expression">
checked="checked"
</if>
</macro>

<input type="checkbox" name="mycheckbox" ${Checked()} />

but Spark cannot parse it.

Tim Schmidt

unread,
Aug 4, 2008, 2:48:31 PM8/4/08
to spar...@googlegroups.com
Why not just do...

<input type="checkbox" name="mycheckbox" ${expression ? "checked" : ""}>

Louis DeJardin

unread,
Aug 4, 2008, 3:35:05 PM8/4/08
to spar...@googlegroups.com
At the moment expressions can appear in element text-content, or as
attribute text-value... Something would need to be done to enable
producing element attributes.

Chadly

unread,
Aug 4, 2008, 3:35:16 PM8/4/08
to Spark View Engine Dev
When I do that, it gives me the same "unable to parse view" error. I
think it has to do with Spark expecting valid xml markup.

On Aug 4, 1:48 pm, "Tim Schmidt" <t...@schmidthole.com> wrote:
> Why not just do...
>
> <input type="checkbox" name="mycheckbox" ${expression ? "checked" : ""}>
>

Tim Schmidt

unread,
Aug 4, 2008, 3:56:11 PM8/4/08
to spar...@googlegroups.com
Hmm... definitely seems like Lou might've broken something with the parser then.  I'm like 95% sure I did something exactly like that in the past.

Louis DeJardin

unread,
Aug 4, 2008, 4:40:42 PM8/4/08
to spar...@googlegroups.com
Nope... You would never have been able to create an attribute with an
expression. Just the attribute's value.

Until that's implemented is there a helper you could use to create the checkbox?


On 8/4/08, Tim Schmidt <t...@schmidthole.com> wrote:

Chadly

unread,
Aug 4, 2008, 4:47:42 PM8/4/08
to Spark View Engine Dev
For now, since it was a relatively simple case, I just did this:

<if condition="expression">
<input type="checkbox" checked="checked" />
<else>
<input type="checkbox" />
</else>

even though it is repetitive.

On Aug 4, 3:40 pm, "Louis DeJardin" <louis.dejar...@gmail.com> wrote:
> Nope... You would never have been able to create an attribute with an
> expression. Just the attribute's value.
>
> Until that's implemented is there a helper you could use to create the checkbox?
>
> On 8/4/08, Tim Schmidt <t...@schmidthole.com> wrote:
>
> > Hmm... definitely seems like Lou might've broken something with the parser
> > then.  I'm like 95% sure I did something exactly like that in the past.
>

Louis DeJardin

unread,
Aug 4, 2008, 5:00:58 PM8/4/08
to Spark View Engine Dev
For that one I think I'd propose taking an expresion that results in a
dictionary, or a class whose properties are treated like a dictionary.
That way you could provide any number of name-value pairs which could
be rendered as name="value" attributes.

<input type="checkbox" ${isChecked ? new {checked="checked"} : null} /
>

or you could keep the checked attribute in a var

<var checked="new {checked='checked', @class='checkedstyle'}" />

<input type="checkbox" ${isChecked ? checked : null} />


And of course there's always the potential to support an expression
that results in a string to simply be rendered.

Thoughts?
Reply all
Reply to author
Forward
0 new messages