             />
         }
         {
-          lastMenu = @state.nowLastMenu
-          if !lastMenu? || !lastMenu.sub?
-            valid = @state.applyEnabled
-            <Button disabled={!valid} onClick={@handleAddRule}>{__ 'Apply'}</Button>
+          applyHidden = lastMenu? && (lastMenu.sub? || lastMenu.value == 'none')
+          if applyHidden
+            style = {display: 'none'}
+            valid = true
+          else
+            style = {}
+            if lastMenu.value?
+              valid = true      # value=='none' is eliminated at applyHidden
+            else
+              valid = lastMenu.applyEnabledFunc? @state.nowMenuPath, @state.inputText
+              valid ?= true
+          <Button disabled={!valid} onClick={@handleAddRule} style={style}>
+            {__ 'Apply'}
+          </Button>
         }
       </form>
     </Panel>

RuleSelectorMenu = React.createClass
  getInitialState: ->
    nowMenuPath: ['_root']
    nowLastMenu: menuTree['_root']
    ruleValue: null
    applyEnabled: false
    errorText: null

  handleDropdownChange: (level, e) ->
    path = @state.nowMenuPath[0..level]
    path.push e.target.value
    totalDetails = accumulateMenu path
    @clearErrorText()
    @setState
      nowMenuPath: path
      nowLastMenu: totalDetails
      applyEnabled: totalDetails.value?
      ruleValue: totalDetails.value

  handleTextChange: (e) ->
    path = @state.nowMenuPath
    nowMenu = @state.nowLastMenu
    value = e.target.value
    @setState
      applyEnabled: !nowMenu.applyEnabledFunc? || nowMenu.applyEnabledFunc path, value
      ruleValue: value

  handleAddRule: ->
    path = @state.nowMenuPath.slice()
    menu = @state.nowLastMenu
    preprocess = menu.preprocess || ((path, value) -> value)
    value = cloneByJson(preprocess(path, @state.ruleValue))
    if menu.testError? && (errorText = menu.testError path, value)?
      @setState {errorText}
    else
      @props.onAddRule? path, value

  clearErrorText: ->
    @setState
      errorText: null

  render: ->
    <Panel collapsible defaultExpanded header={__ 'Filter'}>
      <form className='form-horizontal'>
        <ListGroup fill>


              # A text input
              else
                <StatefulInputText onChange={@handleTextChange}
                  key={"text-#{level}-#{id}"}
                  {...options} />
         }
        </ListGroup>
