| javascript_core

# Class: Bs_FormFieldSelect Source Location: /core/form/Bs_FormFieldSelect.class.js.php
### Class Overview
example usage: | ### Methods addElementsByHash getAllKeys getAllOptions getTextForValue getValue getValueOrText hasValue init moveAllTo moveHashTo moveSelectedTo moveTo prune removeElement setText setTo sortByKey sortByText
### Inherited Variables | ### Inherited Methods
### Class Details [line 25] example usage: you have a select field in your page, it looks like <select name="something" id="yourSelectFieldId"><option value="foo"><bar></option></select> now you get a reference to it using var myField = document.getElementById('yourSelectFieldId'); then you need to create an instance of Bs_FormFieldSelect (only one for all select fields). s = new Bs_FormFieldSelect(); and then you give your select form field the functionality of the bs class: s.init(myField); that's it, now you can use things like: myField.getValue(), myField.hasValue() etc naming: while we usually call the elements of a hash table key and value, for the html select field they are called value and text. so key=value and value=text. might be a bit confusing. [ Top ] ### Class Methods ### method addElementsByHash [line 308]
`int addElementsByHash( object dataHash dataHash)`
adds the elements from the given hash to the select field. #### Tags:
return: | (number of elements added)
access: | public
#### Parameters:
object dataHash | dataHash | (hash)
[ Top ] ### method getAllKeys [line 268]
`array getAllKeys( )`
returns all keys of the elements of this field (not just the selected ones). #### Tags:
return: | (vector)
access: | public
[ Top ] ### method getAllOptions [line 284]
`array getAllOptions( )`
returns all key/value pairs of all the options of the field. like in getValueOrText(), if the value is empty (or not set), the text is used as key too. #### Tags:
return: | (hash)
access: | public
[ Top ] ### method getTextForValue [line 116]
`string getTextForValue( mixed value)`
returns the text for the value specified. (in other words, the value for the given key.) #### Tags:
since: | bs4.5
throws: | bool false (if no element with such a value exists)
access: | public
#### Parameters:
mixed | value | value
[ Top ] ### method getValue [line 54]
`string getValue( )`
returns the value. if the value is not present: depending on the browser, the text (between the <option></option> tags) or an empty string is returned. #### Tags:
see: | Bs_FormFieldSelect::getValueOrText()
throws: | (string) 'undefined'
access: | public
[ Top ] ### method getValueOrText [line 88]
`string getValueOrText( int selIndex)`
returns the value, or, if not specified, the text. an option tag can be written as <option>foo</option> or <option value="foo">foo</option>. if submitted to the server, it does not matter. but in js it does, for example ie6 thinks the first one has no value. the browser thinks that <option>foo</option> and <option value="">foo</option> both have the value "". but that is a big problem. because if submitted to the server, the first one will be submitted as "foo" while the 2nd will be submitted as "". in other words, this method returns the same value as the browser would submit to the server. example return values: <option></option> = "" <option>foo</option> = foo <option value="">foo</option> = "" <option value="foo">foo</option> = foo #### Tags:
since: | bs4.4
see: | Bs_FormFieldSelect::getValue()
throws: | bool false
access: | public
#### Parameters:
int | selIndex | i (the index of the option you want, if not specified then the currently selected one (this.selectedIndex) will be used.)
[ Top ] ### method hasValue [line 33]
`void hasValue( mixed val)`
tells if the select field has an option with the given value (key, not text). #### Tags:
access: | public
#### Parameters:
mixed | val | val
[ Top ] ### method init [line 401]
`void init( object formField formField)`
#### Tags:
access: | public
#### Parameters:
object formField | formField |
[ Top ] ### method moveAllTo [line 184]
`bool moveAllTo( mixed toField)`
takes all optons in this field and moves them to the given field. #### Tags:
see: | this.moveSelectedTo(), this.moveHashTo(), this.moveTo()
access: | public
#### Parameters:
mixed | toField | toField (string = the field id, object = reference to the field.)
[ Top ] ### method moveHashTo [line 241]
`bool moveHashTo( mixed toField, array hash)`
moves the option elements from the given hash from this field to the given select field, thus removing them in this field. #### Tags:
see: | this.oveSelectedTo(), this.moveAllTo(), this.moveTo()
access: | public
#### Parameters:
mixed | toField | toField (string = the field id, object = reference to the field.)
array | hash | hash (key is the id (value of the select field), value is bool true)
[ Top ] ### method moveSelectedTo [line 156]
`bool moveSelectedTo( mixed toField, bool keepSelected)`
takes the selected optons in this field and moves them to the given field. the options are still selected in the other field if keepSelected is set to true. #### Tags:
see: | this.moveHashTo(), this.moveAllTo(), this.moveTo()
todo: | implement functionality for keepSelected param
access: | public
#### Parameters:
mixed | toField | toField (string = the field id, object = reference to the field.)
bool | keepSelected | keepSelected (not implemented yet)
[ Top ] ### method moveTo [line 210]
`bool moveTo( string toField, mixed optionValue)`
moves the option specified to the field specified. #### Tags:
see: | this.moveSelectedTo(), this.moveHashTo(), this.moveAllTo()
access: | public
#### Parameters:
string | toField | optionValue (the .value attribute of the option you want to move, it's the key not the text!)
[ Top ] ### method prune [line 297]
`void prune( )`
empties the select field (removes all options). #### Tags:
access: | public
[ Top ] ### method removeElement [line 385]
`bool removeElement( mixed value)`
removes the element with the value specified. #### Tags:
return: | true on success, false if that value does not exist.
since: | bs4.5
access: | public
#### Parameters:
mixed | value | value (the 'key', not the text!)
[ Top ] ### method setText [line 368]
`bool setText( mixed value, string text)`
sets the 'text' of the 'value'=>'text' pair. #### Tags:
return: | true on success, false if that value does not exist.
since: | bs4.5
access: | public
#### Parameters:
mixed | value | value (the 'key', not the text!)
string | text | text (the new text to set)
[ Top ] ### method setTo [line 133]
`bool setTo( string compare, string type)`
selects the entry in the select field with the value or text specified. #### Tags:
return: | true on success, false if that value does not exist.
access: | public
#### Parameters:
string | compare | compare (the thing to compare)
string | type | type ('value' (=key) or 'text' (=value). default is 'text'.)
[ Top ] ### method sortByKey [line 355]
`void sortByKey( )`
#### Tags:
todo: | all
[ Top ] ### method sortByText [line 327]
`void sortByText( bool desc, bool natural)`
sorts the array elements by the text (caption). #### Tags:
todo: | implement the natural order thing
access: | public
#### Parameters:
bool | desc | desc (by default we order ascending, set this to true if you want descending.)
bool | natural | natural (set to true if you want "natural" ordering.)
[ Top ] Documentation generated on Mon, 29 Dec 2003 22:18:24 +0100 by phpDocumentor 1.2.3