2017-07-31 62 views
1

我有團隊和競爭的註冊部分,但我想要做的是當用戶選擇競爭時我試圖顯示促銷代碼字段,該字段將只顯示時如果選擇了團隊,則選擇競賽,但不會顯示促銷領域,這要感謝提前預覽。試圖根據選定的選項顯示字段

 React.Component { 
      constructor(props) { 
      super(props); 
      this.state = {name: '', email: '', password: ''}; 
      } 

      handleChange(event) { 
      this.setState({ [event.target.name]: event.target.value }); 
      } 

      handleSelect(event, index, value) { 
      this.setState({type: value}); 
      } 

      handleSignup(event) { 
      event.preventDefault(); 
      this.props.dispatch(signup(this.state.name, this.state.email, this.state.password, this.state.promo, this.state.type)); 
      } 



      render() { 
      return (
       <div className="login"> 
       <div className="panel"> 
        <div className="body"> 
        <legend>Create an account</legend> 
        <SelectField 
         floatingLabelText="User or Admin" 
         value={this.state.type} 
         name="type" id="type" 
         onChange={this.handleSelect.bind(this)} 
        > 
         <MenuItem value={"USER"} primaryText="User" /> 
         <MenuItem value={"ADMIN"} primaryText="Admin" /> 
        </SelectField> 

        <TextField 
         hintText="Promo Code" 
         name="promo" id="promo" autoFocus 
         value={this.state.code} onChange={this.handleChange.bind(this)} 
         floatingLabelText="Promo Code" 
        /> 
+2

你期待你寫顯示代碼/隱藏促銷字段?還是你問如何編寫代碼? – Lewis42

回答

0

呈現文本字段「促銷代碼」有條件只有當國家的種類中,「競爭」:

環繞聲場與{ condition ? <YourField.../> : null }

{this.state.type === 'COMPETITION' 
     ? <TextField 
      hintText="Promo Code" 
      name="promo" id="promo" autoFocus 
      value={this.state.code} onChange={this.handleChange.bind(this)} 
      floatingLabelText="Promo Code" 
     /> 
     : null} 
+0

我也在嘗試驗證促銷代碼,並且我想要對促銷代碼進行硬編碼,用戶必須輸入該代碼,並且必須驗證其中的任何想法? – niharb

+0

我正在嘗試使用onBlur添加一個函數來檢查輸入是否與所需的單詞匹配。但需要一點幫助 – niharb

+0

這已經是下一個問題了。請在StackOverflow上單獨提問。你能否按照我在答案中的建議「按照選定的選項顯示字段」來運行? –

相關問題