Example usage for com.google.gwt.dom.client OptionElement getValue

List of usage examples for com.google.gwt.dom.client OptionElement getValue

Introduction

In this page you can find the example usage for com.google.gwt.dom.client OptionElement getValue.

Prototype

public String getValue() 

Source Link

Document

The current form control value.

Usage

From source file:com.arcbees.chosen.client.ChosenImpl.java

License:Apache License

private void resultsReset() {
    OptionElement firstoption = selectElement.getOptions().getItem(0);
    selectedValues = new ArrayList<String>();

    if (firstoption != null) {
        firstoption.setSelected(true);/*from   w  ww .  ja v a2  s.com*/
        selectedValues.add(firstoption.getValue());
    }

    resetSelectedItem();

    showSearchFieldDefault(defaultText);
    resultsResetCleanup();

    fireEvent(new ChosenChangeEvent(null, 0, this));

    if (activeField) {
        resultsHide();
    }
}

From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java

License:Apache License

/**
 * Return the values of all selected options in an array.
 * Usefull to know which options are selected in case of multiple ChosenListBox
 *
 * @return the values of all selected options in an array
 *///www.ja v  a 2  s.c o  m
public String[] getValues() {
    ChosenImpl impl = getChosenImpl();

    if (impl != null) {
        List<String> selectedValues = impl.getSelectedValues();
        return selectedValues.toArray(new String[selectedValues.size()]);
    } else {
        JsArrayString values = JsArrayString.createArray().cast();
        NodeList<OptionElement> options = SelectElement.as(getElement()).getOptions();
        for (int i = 0; i < options.getLength(); i++) {
            OptionElement option = options.getItem(i);
            if (option.isSelected()) {
                values.push(option.getValue());
            }
        }

        String[] result = new String[values.length()];
        for (int i = 0; i < values.length(); i++) {
            result[i] = values.get(i);
        }

        return result;
    }
}

From source file:com.arcbees.chosen.client.SelectParser.java

License:Apache License

private void addOption(OptionElement option, int groupPosition, boolean groupDisabled) {
    String optionText = option.getText();

    OptionItem item = new OptionItem();
    item.arrayIndex = parsed.size();/*  w  w w.jav a  2s.  c o  m*/
    item.optionsIndex = optionsIndex;

    if (optionText != null && optionText.length() > 0) {

        if (groupPosition != -1) {
            ((GroupItem) parsed.get(groupPosition)).children++;
        }

        item.value = option.getValue();

        item.text = option.getLabel();
        if (isNullOrEmpty(item.text)) {
            item.text = option.getText();
        }

        item.html = option.getInnerHTML();
        item.selected = option.isSelected();
        item.disabled = groupDisabled ? groupDisabled : option.isDisabled();
        item.groupArrayIndex = groupPosition;
        item.classes = option.getClassName();
        item.style = getCssText(option.getStyle());
        item.empty = false;

    } else {
        item.empty = true;
        item.groupArrayIndex = -1;
    }

    parsed.add(item);
    optionsIndex++;
}

From source file:com.bearsoft.gwt.ui.widgets.StyledListBox.java

public String getKey(int aIndex) {
    OptionElement option = getItem(aIndex);
    return option.getValue();
}

From source file:com.brazoft.foundation.gwt.client.ui.api.Combo.java

License:Apache License

protected C select(String value) {

    for (OptionElement option : this.options()) {
        option.setSelected(option.getValue().equals(value));
    }/*w w w.j av  a  2 s  .  c o  m*/

    this.select(this.getId(), value);

    return (C) this;
}

From source file:com.tractionsoftware.gwt.user.client.ui.GroupedListBox.java

License:Apache License

@Override
public String getValue(int index) {
    OptionElement option = getOption(index);
    return option.getValue();
}

From source file:com.uni.hs13.visupoll.client.OptGroupListBox.java

License:Apache License

/**
 * Adds a new OPTION item to the ListBox. If the <em>key</em> of this item already exists, the
 * item will <strong>not</strong> be created (existing <em>label</em> is fine, though). Otherwise
 * it will be added to the last created OPTGROUP item. If no OPTGROUP item exists, the OPTION item
 * will be created without a OPTGROUP parent item.
 * //from   w w  w  .jav a2s.  c om
 * @param key the key of the OPTION item
 * @param label the label of the OPTION item
 * @return {@code true}, if the key of the item does not already exist, otherwise {@code false}.
 */
public boolean addGroupItem(final String key, final String label) {
    // check if this item already exists
    SelectElement selectElement = this.getElement().cast();
    NodeList<Element> elementsByTagName = selectElement.getElementsByTagName("*");

    for (int i = 0; i < elementsByTagName.getLength(); i++) {
        Element item = elementsByTagName.getItem(i);

        if (OptGroupListBoxItemType.OPTION.getItemNodeName().equals(item.getNodeName())) {
            OptionElement castedElement = (OptionElement) item;
            if (castedElement.getValue().equals(key)) {
                return false;
            }
        }
    }

    // okay, it does not already exist... create it
    if (latestOptGroupElement == null) {
        this.addItem(label, key);
    } else {
        OptionElement optElement = Document.get().createOptionElement();
        optElement.setInnerText(label);
        optElement.setValue(key);
        latestOptGroupElement.appendChild(optElement);
    }
    return true;
}

From source file:com.watopi.chosen.client.ChosenImpl.java

License:Open Source License

private void resultDeselect(int index) {
    OptionItem item = (OptionItem) selectItems.get(index);

    item.setSelected(false);/*from www . ja  va 2 s  .c om*/

    // select option in original element
    OptionElement option = selectElement.getOptions().getItem(item.getOptionsIndex());
    option.setSelected(false);

    $("#" + containerId + "_o_" + index).removeClass(css.resultSelected()).addClass(css.activeResult()).show();

    resultClearHighlight();
    winnowResults();

    fireEvent(new ChosenChangeEvent(option.getValue(), false, this));

    searchFieldScale();
}

From source file:com.watopi.chosen.client.SelectParser.java

License:Open Source License

private void addOption(OptionElement option, int groupPosition, boolean groupDisabled) {
    String optionText = option.getText();

    OptionItem item = new OptionItem();
    item.arrayIndex = parsed.length();/*from   ww  w .  ja va 2  s.com*/
    item.optionsIndex = optionsIndex;

    if (optionText != null && optionText.length() > 0) {

        if (groupPosition != -1) {
            ((GroupItem) parsed.get(groupPosition)).children++;
        }

        item.value = option.getValue();
        item.text = option.getText();
        item.html = option.getInnerHTML();
        item.selected = option.isSelected();
        item.disabled = groupDisabled ? groupDisabled : option.isDisabled();
        item.groupArrayIndex = groupPosition;
        item.classes = option.getClassName();
        item.style = getCssText(option.getStyle());
        item.empty = false;

    } else {
        item.empty = true;
        item.groupArrayIndex = -1;

    }

    parsed.add(item);
    optionsIndex++;
}

From source file:org.kaaproject.avro.ui.gwt.client.widget.ExtendedValueListBox.java

License:Apache License

private void updateOptionsStyle() {
    if (Utils.isNotBlank(promptText)) {
        SelectElement select = getSelectElement();
        int index = select.getSelectedIndex();
        if (index > -1) {
            OptionElement selectedOption = getOptionElement(index);
            if (Utils.isBlank(selectedOption.getValue())) {
                selectedOption.setClassName(style.prompt());
                selectedOption.setText(promptText);
                addStyleName(style.prompt());
                NodeList<OptionElement> options = getSelectElement().getOptions();
                for (int i = 0; i < options.getLength(); i++) {
                    if (index != i) {
                        OptionElement option = options.getItem(i);
                        option.setClassName(style.noPrompt());
                    }/*  www  .  ja  va 2 s. c  o  m*/
                }
            } else {
                NodeList<OptionElement> options = getSelectElement().getOptions();
                for (int i = 0; i < options.getLength(); i++) {
                    OptionElement option = options.getItem(i);
                    if (Utils.isBlank(option.getValue())) {
                        option.setClassName("");
                        option.setText("");
                    }
                }
                removeStyleName(style.prompt());
            }
        }
    }
}