如果条件为真,则添加className

问题描述 投票:0回答:2

我有一个包含多个字段的表单和一个提交按钮。一旦我单击提交按钮,它将进入此filterProperties功能。我在filterProperties函数中有一个if条件。所以在这种情况下,我正在检查退房日期是否为空。如果if条件为true,我想将has-error类添加到datepicker。如果有人知道该怎么做,请帮忙。

      filterProperties = () => {
        let checkin = this.state.checkin;
        let checkout = this.state.checkout;
        let guestCount = this.state.guest_count;
        let cityID = this.state.selectedcityID;
        let budget = parseFloat(this.state.textthree).toFixed(2);
        if (checkin !== "" && checkout === '') {
            alert('plz enter the check out date');
        }

        const cityProperties = {
            checkin: checkin,
            checkout: checkout,
            guestCount: guestCount,
            cityID: cityID,
            budget: budget
        }
        console.log(cityProperties);
        this.props.getCityProperties(cityProperties);
    }
                  <FormItem style={{ marginBottom: '0' }} label="Check Out">
                        <span>
                            {getFieldDecorator('check_out', {
                                rules: [
                                    {
                                        required: true,
                                        message: 'Please select a Check Out Date',
                                    }, {
                                        validator: this.checkCheckoutDates,
                                    }
                                ],
                            })(<DatePicker
                                className={className}
                                disabled={(this.state.checkin === '')}
                                disabledDate={this.disabledDateCheckout}
                                onChange={(e) => this.dateSelected(e, 'checkout')}
                                defaultValue={moment(new Date((new Date()).valueOf() + 1000 * 60 * 60 * 24))}
                                format={dateFormat}
                            />)}
                        </span>
                    </FormItem>
css reactjs classname
2个回答
0
投票
<DatePicker className={(this.state.checkin !== "" && this.state.checkout === "")? "class-name": ""} disabled={(this.state.checkin === '')} disabledDate={this.disabledDateCheckout} onChange={(e) => this.dateSelected(e, 'checkout')} defaultValue={moment(new Date((new Date()).valueOf() + 1000 * 60 * 60 * 24))} format={dateFormat} />

0
投票
<Element className={`${this.state.flag ? className : ''}`} />
© www.soinside.com 2019 - 2024. All rights reserved.