XForms provides two separate controls for selecting items from a list. The first is select, which presents a list to the user and allows them to choose as many items as they like, whilst the second is select1 which limits the user to one selection.
The del.icio.us add method has an optional parameter called replace which indicates whether the data being submitted should overwrite any existing data. If the value is anything but no then the data will be overwritten. We can provide the user with a way to set this value by using a select1 control.
The select1 control has all of the same features that an input has--such as hint, help, and so on--but in addition supports the item element to provide choices that the user is able to select from. For the del.icio.us form we need two choices, "yes" and "no".
The following mark-up gives us a select1 with these two choices, and a hint to help the user. Add it to your form, just before the submit button:
</xf:input>
<xf:select1 ref="replace">
<xf:label>Replace:</xf:label>
<xf:hint>
Set this to <em>no</em> to prevent
del.icio.us from overwriting a previous entry
for the same link, if one exists.
</xf:hint>
<xf:item>
<xf:label>Yes</xf:label>
<xf:value>yes</xf:value>
</xf:item>
<xf:item>
<xf:label>No</xf:label>
<xf:value>no</xf:value>
</xf:item>
</xf:select1>
<xf:submit submission="sub-add-link" ref="extended">
You'll also need to add the same relevance rule that we use for extended and dt, so that the control is hidden until a URL and a title have been entered:
<xf:bind nodeset="extended" relevant="../url != '' and ../description != ''" />
<xf:bind nodeset="dt" relevant="../url != '' and ../description != ''" />
<xf:bind nodeset="replace" relevant="../url != '' and ../description != ''" />
<xf:bind nodeset="dt" type="xsd:date" />
</xf:model>
And finally, to get the formatting right, you'll also want to add to the CSS rules:
xf\:input,
xf\:select1,
xf\:textarea,
xf\:output
{
.
.
.
}
.input-value,
.select1-value,
.textarea-value
{
.
.
.
}
xf\:input xf\:label,
xf\:select1 xf\:label,
xf\:textarea xf\:label
{
.
.
.
}
If you save the form and then refresh it in the browser, your form should look something like this:
The default display of the select1 that we just added was a drop-box. Howevever, often when there are only a couple of choices we would rather have them displayed as radio buttons. This is easily done in formsPlayer by adding the appearance attribute and giving it a value of full:
<xf:select1 ref="replace" appearance="full">
<xf:label>Replace:</xf:label>
.
.
.
</xf:select1>Just to be clear, this attribute doesn't mean 'please give me radio buttons'--instead it informs an XForms processor that the author would like as many of the choices in the list to be available to the user as possible. Of course, how that actually pans out and gets implemented will be different on different systems; the effect of this on a voice-based XForms processor will be different to the effect on a GUI-based one, and different again to a mobile phone.
But the idea is that there is at least some similarity in the way this is implemented, and the author is in effect providing a 'hint' to the processor about what they would like to happen. In the case of formsPlayer, when appearance is set to full on a select1 then all of the options in the list are made available via radio buttons: