You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@click.apache.org by "Bob Schellink (JIRA)" <ji...@apache.org> on 2013/08/14 07:49:47 UTC

[jira] [Closed] (CLK-797) Select with only one option, Select isValid() return error when this option select in browser.

     [ https://issues.apache.org/jira/browse/CLK-797?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bob Schellink closed CLK-797.
-----------------------------

    Resolution: Not A Problem

Hi, this is the intended behavior. If your select doesn't have a default "not selected" option then you should switch off validation. Reason is that HTML select always has a selected value, the first option. So if Select required is enabled, Click will raise an error if the first option is selected. So either switch off required or add a default "no selected" option.
                
> Select with only one option, Select isValid() return error when this option select in browser.
> ----------------------------------------------------------------------------------------------
>
>                 Key: CLK-797
>                 URL: https://issues.apache.org/jira/browse/CLK-797
>             Project: Click
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 2.3.0
>         Environment: Windows 7, Tomcat 7.0, JDK 1.6
>            Reporter: Zhang Xiaohe
>            Priority: Minor
>              Labels: Form, Option, Select, isValid
>
> I have development a page, 
> this page struct:
>    SettingsPage
>         |
>         | ---> Table
>         |
>         | ---> Form
>                   |
>                   | ----> Select
>                   |            |
>                   |            | ---> Option (Only one option from DataProvider)
>                   |
>                   | ----> TextField
>                   |
>                   | --->  Submit ( my logic call onConfigFromSubmit) 
> when I select option, and input some content to TextField, and click Submit,
> the method onConfigFromSubmit invoke, and I check Form isValid() , the select return false.
> My Code fragment:
> package com.vhly.servers.innerstore.pages;
> import com.vhly.servers.innerstore.InnerConfigUtil;
> import com.vhly.servers.innerstore.model.ConfigValuePair;
> import org.apache.click.Page;
> import org.apache.click.control.*;
> import org.apache.click.dataprovider.DataProvider;
> import org.apache.click.extras.control.FieldColumn;
> import org.apache.click.util.Bindable;
> import java.util.LinkedList;
> import java.util.List;
> /**
>  * Created by IntelliJ IDEA.
>  * User: vhly[FR]
>  * Date: 13-8-13
>  * Email: vhly@163.com
>  */
> public class SettingsPage extends Page {
>     private Form configForm = new Form("configEditor");
>     private Table table = new Table("configs");
>     public SettingsPage() {
>         table.setClass(Table.CLASS_ITS);
>         table.addColumn(new Column("name"));
>         table.addColumn(new Column("value"));
>         table.setDataProvider(new DataProvider() {
>             @Override
>             public Iterable getData() {
>                 InnerConfigUtil configUtil = InnerConfigUtil.getInstance();
>                 return configUtil.getAllProperties();
>             }
>         });
>         addControl(table);
>         addControl(configForm);
>         Select select = new Select("property", true);
>         select.setDataProvider(new DataProvider() {
>             @Override
>             public Iterable getData() {
>                 InnerConfigUtil configUtil = InnerConfigUtil.getInstance();
>                 List<ConfigValuePair> allProperties = configUtil.getAllProperties();
>                 List<Option> options = new LinkedList<Option>();
>                 for (ConfigValuePair valuePair : allProperties) {
>                     String name = valuePair.getName();
>                     options.add(new Option(name, name));
>                 }
>                 return options;
>             }
>         });
>         configForm.add(select);
>         configForm.add(new TextField("value", true));
>         configForm.add(new Submit("OK"));
>         configForm.setListener(this, "onConfigFromSubmit");
>     }
>     public boolean onConfigFromSubmit() {
>         boolean bret = false;
>         if (configForm.isValid()) {   // In this case, only one option will return false from Select.isValid()
>             String name = configForm.getFieldValue("property");
>             String value = configForm.getFieldValue("value");
>             InnerConfigUtil configUtil = InnerConfigUtil.getInstance();  // my logic
>             configUtil.setProperty(name, value);
>             bret = true;
>         }
>         return bret;
>     }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira