Hi Jason

On Thu, Feb 12, 2015 at 8:54 AM, Jason Clemons <[email protected]> wrote:
> Hey Marius,
>
> Thanks for responding...my form has multiple comboboxes each having a value 
> of essentially "Select a status" or "Select a type" etc..as the 0 index for 
> each..while indexes 1 thru N are valid selections, index selection 0 will 
> never be  a valid selection since its the default prompt.
>
> Initially I tried using the ID of the combobox as an index (e.g..selection 0 
> is "Select a status|0") and I was planning on using that 0 for validation 
> logic.  However, I ended up needing the ID meta for another purpose related 
> to my application downstream.
>
> Ultimately I ended up writing code that says if combobox value = "Select 
> status" then prevent page save.  However, this approach doesn't really scale 
> all that well because I have multiple comboboxes on my form which all have 
> different default values at index 0 (depending on the context of the 
> combobox). However what is always true in my entire form is that index 0 of 
> any combobox is never a valid selection, so I was hoping to access that  to 
> determine if the user actually selected a value or left the default.
>
> This type of thing is a pretty common attribute of UI elements in other 
> programming environments so I was thinking that the controls in Xwiki might 
> have something similar.  I can certainly work around it (and I have for my 
> current solution) but really wanted to know for future use.

There is a very simple solution. You have to know that the text you
see in the combo box (drop down / select) doesn't have to be the value
that is actually submitted to the server. Each option can have a label
(what is displayed) and a value (what is submitted). You should
checkout the select HTML element
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select . You
can have something like:

<select name="type">
  <option value="">Select a type</option>
  <option value="science">Science Articles</option>
  ...
</select>

Then you can validate that the submitted value is not empty.

>
> Thanks again for taking the time
> to respond, the support you guys give is SUPER valuable to me and keeps me 
> moving forward in most cases, so I really appreciate it.

I'm glad to hear that ;)

Hope this helps too,
Marius

>
>> On Feb 11, 2015, at 11:11 PM, Marius Dumitru Florea 
>> <[email protected]> wrote:
>>
>> A combo box (drop down, select) is just an UI element. What is saved
>> in the database (and thus what you can query) is normally the selected
>> raw value(s) and maybe the list of supported raw values (what you can
>> choose from). Sometimes the labels (display values) are also stored in
>> the database. But I've never heard of storing the indexes, **unless**
>> the index is the value. Why do you need the index? The index is very
>> fragile as you can add new supported values and the order can changed.
>>
>> Hope  this helps,
>> Marius
>>
>>> On Thu, Feb 12, 2015 at 2:19 AM, Jason Clemons <[email protected]> 
>>> wrote:
>>> is this not possible?
>>>
>>>
>>>
>>>> On Feb 3, 2015, at 8:56 AM, Jason Clemons <[email protected]> wrote:
>>>>
>>>> Hello all,
>>>>
>>>> I have no issue getting the value of a combo box control in HQL using 
>>>> "ComboBoxName.value = 'foobar'" but is there a way to get the selected 
>>>> index of the combobox in my query?
>>>> _______________________________________________
>>>> users mailing list
>>>> [email protected]
>>>> http://lists.xwiki.org/mailman/listinfo/users
>>> _______________________________________________
>>> users mailing list
>>> [email protected]
>>> http://lists.xwiki.org/mailman/listinfo/users
>> _______________________________________________
>> users mailing list
>> [email protected]
>> http://lists.xwiki.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to