client/components/RSVPForm.component.js
/**
     * Validates that the form can be submitted and returns null on success or a string message with
     * the validation error otherwise.
     */
Validates that the form can be submitted and returns null on success or a string message with
the validation error otherwise.
Validates that the form can be submitted and returns null on success or a string message with the validation error otherwise .
validate() {
        function validateGuestDetail(info) {
            if (!info.meal)
                return "Please let us know of your or your guest's meal preference";
            return null;
        }
        const guestInfo = this.state.guestInfo;
        if (!guestInfo.name || guestInfo.name.trim().empty)
            return 'Please give us your name';
        if (!guestInfo.attendance)
            return 'Please specify whether you will be joining us';
        if (guestInfo.attendance === 'no')
            return null;
        if (!guestInfo.email || guestInfo.email.trim().empty || !isEmail(guestInfo.email))
            return 'Please give us your valid email';
        if (!guestInfo.address)
            return 'Please provide your address so we can send you your invitation';
        const guestPlusOneInfo = this.state.guestPlusOneInfo;
        if (!guestPlusOneInfo.attendance)
            return 'Please let us know whether you will be bringing a plus one';
        if (guestInfo.attendance === 'yes')
            return null;
        const guestValidation = validateGuestDetail(guestInfo);
        if (guestValidation) {
            return guestValidation;
        }
        if (guestPlusOneInfo.attendance === '1')
            return null;
        if (!guestPlusOneInfo.name || guestPlusOneInfo.name.trim().empty)
            return 'The plus one name field cannot be left empty';
        return validateGuestDetail(guestPlusOneInfo);
    }
validate ( ) { function validateGuestDetail ( info ) { if ( ! info . meal ) return "Please let us know of your or your guest's meal preference" ; return null ; } const guestInfo = this . state . guestInfo ; if ( ! guestInfo . name || guestInfo . name . trim ( ) . empty ) return 'Please give us your name' ; if ( ! guestInfo . attendance ) return 'Please specify whether you will be joining us' ; if ( guestInfo . attendance === 'no' ) return null ; if ( ! guestInfo . email || guestInfo . email . trim ( ) . empty || ! isEmail ( guestInfo . email ) ) return 'Please give us your valid email' ; if ( ! guestInfo . address ) return 'Please provide your address so we can send you your invitation' ; const guestPlusOneInfo = this . state . guestPlusOneInfo ; if ( ! guestPlusOneInfo . attendance ) return 'Please let us know whether you will be bringing a plus one' ; if ( guestInfo . attendance === 'yes' ) return null ; const guestValidation = validateGuestDetail ( guestInfo ) ; if ( guestValidation ) { return guestValidation ; } if ( guestPlusOneInfo . attendance === '1' ) return null ; if ( ! guestPlusOneInfo . name || guestPlusOneInfo . name . trim ( ) . empty ) return 'The plus one name field cannot be left empty' ; return validateGuestDetail ( guestPlusOneInfo ) ; }
Validates that the form can be submitted and returns null on success or a string message with
 the validation error otherwise.
Validates that the form can be submitted and returns null on success or a string message with the validation error otherwise .