Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: mdbreact scrolling modal

Mini Mirana free asked 5 years ago


<MDBModal isOpen={this.state.addModal}>
    <form className="needs-validation" onSubmit={this.handleStudentAdd} noValidate>
      <MDBModalHeader className="text-center text-default" titleClass="w-100 font-weight-bold" toggle={this.toggleAdd}>
       Add New Student
     </MDBModalHeader>
     <MDBModalBody>
         <MDBInput type="text" label="Firstname" name="firstname" required containerClass={"mb-5 mx-3"}>
             <div className="valid-feedback">Looks good!</div>
             <div className="invalid-feedback">Please provide a valid firstname.</div>
         </MDBInput>
         <MDBInput type="text" label="Lastname" name="lastname" required containerClass={"mb-5 mx-3"}>
             <div className="valid-feedback">Looks good!</div>
             <div className="invalid-feedback">Please provide a valid lastname.</div>
         </MDBInput>
         <MDBInput type="text" label="Grade" name="grade" required containerClass={"mb-5 mx-3"}>
             <div className="valid-feedback">Looks good!</div>
             <div className="invalid-feedback">Please provide a valid grade.</div>
        </MDBInput>
        <MDBInput type="text" label="Username" name="username" required containerClass={"mb-5 mx-3"}>
            <div className="valid-feedback">Looks good!</div>
            <div className="invalid-feedback">Please provide a valid username.</div>
         </MDBInput>
         <MDBInput type="password" label="Password" name="password" required containerClass={"mb-5 mx-3"} autoComplete="new-password">
                <div className="valid-feedback">Looks good!</div>
                <div className="invalid-feedback">Please provide a valid password.</div>
         </MDBInput>
         <MDBInput type="text" label="Active" name="active" required containerClass={"mb-5 mx-3"}>
               <div className="valid-feedback">Looks good!</div>
               <div className="invalid-feedback">Please provide a valid active state.</div>
        </MDBInput>
     </MDBModalBody>
     <MDBModalFooter className="justify-content-center">
          <MDBBtn type="submit" >Add Student
               <MDBIcon icon="paper-plane" className="ml-1" />
         </MDBBtn>
     </MDBModalFooter>
  </form>
</MDBModal>

Here is my modal which consists a form.

There was two problems with it:

1) I couldn't scroll modal down as long as it had toggle={this.toggleAdd} in MDBModal>, it was being closed automatically even by clicking on modal's scroll part, so I decided to remove it from there.

2) whenever the modal scrolls it prints _this.props.toggle is not a function in console repeatedly

Am I missing something? how can i fix them?


Edit:

I found the second error was caused by deleting toggle property from MDBMODAL Component but I couldn't fix the first problem(can't scroll)

here is the complete code:

    constructor(props){
        super(props);

        this.state = {
            addModal: false, // Add
        };
    }

    toggleAdd = () => {
        this.setState({
            addModal: !this.state.addModal
        });
    }

    handleStudentAdd = (e) => {
        e.preventDefault()
        e.target.className += " was-validated";
        if(e.target.checkValidity() === true) {
            this.setState((state) => ({
                addModal: !this.state.addModal
            }));
        }
    }

    render(){
        return (
            <div>
                <button onClick={this.toggleAdd} >Click Me!</button>
                <MDBModal isOpen={this.state.addModal}>
                    <form className="needs-validation" onSubmit={this.handleStudentAdd} noValidate>
                        <MDBModalHeader className="text-center text-default" titleClass="w-100 font-weight-bold" toggle={this.toggleAdd}>
                            Add New Student
                        </MDBModalHeader>
                        <MDBModalBody>
                            <MDBInput type="text" label="Firstname" name="firstname" required containerClass={"mb-5 mx-3"}>
                                <div className="valid-feedback">Looks good!</div>
                                <div className="invalid-feedback">Please provide a valid firstname.</div>
                            </MDBInput>
                            <MDBInput type="text" label="Lastname" name="lastname" required containerClass={"mb-5 mx-3"}>
                                <div className="valid-feedback">Looks good!</div>
                                <div className="invalid-feedback">Please provide a valid lastname.</div>
                            </MDBInput>
                            <MDBInput type="text" label="Grade" name="grade" required containerClass={"mb-5 mx-3"}>
                                <div className="valid-feedback">Looks good!</div>
                                <div className="invalid-feedback">Please provide a valid grade.</div>
                            </MDBInput>
                            <MDBInput type="text" label="Username" name="username" required containerClass={"mb-5 mx-3"}>
                                <div className="valid-feedback">Looks good!</div>
                                <div className="invalid-feedback">Please provide a valid username.</div>
                            </MDBInput>
                            <MDBInput type="password" label="Password" name="password" required containerClass={"mb-5 mx-3"} autoComplete="new-password">
                                <div className="valid-feedback">Looks good!</div>
                                <div className="invalid-feedback">Please provide a valid password.</div>
                            </MDBInput>
                            <MDBInput type="text" label="Active" name="active" required containerClass={"mb-5 mx-3"}>
                                <div className="valid-feedback">Looks good!</div>
                                <div className="invalid-feedback">Please provide a valid active state.</div>
                            </MDBInput>
                        </MDBModalBody>
                        <MDBModalFooter className="justify-content-center">
                            <MDBBtn type="submit" >Add Student
                                <MDBIcon icon="paper-plane" className="ml-1" />
                            </MDBBtn>
                        </MDBModalFooter>
                    </form>
                </MDBModal>
            </div>
        )
    }

Piotr Glejzer staff commented 5 years ago

hi,

do you have more code to show? I need to see functions that open/close/toggle modal state and other stuff. Thanks.

Best, Piotr


Mini Mirana free commented 5 years ago

@Piotr Glejzer Sorry for my late reply, I didn't have access to the internet in the last week. I edited my question please check the edit part. thanks :)


Piotr Glejzer staff commented 5 years ago

Thank you very much, I will check it as soon as possible. Have a nice day.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Opened

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: 4.19.2
  • Device: Laptop
  • Browser: Edge, Firefox, Chrome
  • OS: windows 10
  • Provided sample code: No
  • Provided link: No