Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
How can I bind the selected value of a cascading dropdown to a h1 tag in Ant Design?

I am using Ant Design to create a cascading dropdown. I am looking to return the selected value as a tag to display something like "You selected {name}". How can I bind the selected value to the h1 tag? Here is the code so far:

    const options = [
      {
        value: 'Person',
        label: 'person',
        children: [
          {
            value: 'amy',
            label: 'Amy',
          },
          {
           value: 'john',
           label: 'John'
          }
        ],
      }
    ];
    
    function onChange(value, selectedOptions) {
      console.log(value, selectedOptions);
    }
    
    function filter(inputValue, path) {
      return path.some(option => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
    }  
    
    class CascadingDropdown extends Component{
      render(){
            return(
                <div>
                    <p>Please select a person:</p>
                  <div>
                  <Cascader
                      options={options}
                      onChange={onChange}
                      placeholder="Please select"
                      showSearch={{ filter }}
                      onSearch={value => console.log(value)}
                    />
                  </div>
                  <h1>You selected {name}</h1> // here is where I want to print the name
                </div>
            );
        }
    }
    
    export default CascadingDropdown;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use can use state to display the selected value as shown in the following code

const options = [
  {
    value: 'Person',
    label: 'person',
    children: [
      {
        value: 'amy',
        label: 'Amy',
      },
      {
        value: 'john',
        label: 'John',
      },
    ],
  },
];

class CascadingDropdown extends Component {
  onChange(value, selectedOptions) {
    console.log(value, selectedOptions);
    if (value != undefined) {
      this.setState({ name: value[1].toString() });
    }
  }

  filter(inputValue, path) {
    return path.some(
      (option) =>
        option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1
    );
  }

  constructor(props) {
    super(props);
    this.state = {
      name: '',
    };
  }
  render() {
    return (
      <div>
        <p>Please select a person:</p>
        <div>
          <Cascader
            options={options}
            onChange={this.onChange.bind(this)}
            placeholder="Please select"
            showSearch={this.filter}
            onSearch={(value) => console.log(value)}
          />
        </div>
        <h1>You selected {this.state.name}</h1> 
      </div>
    );
  }
}

Screenshot:

Screenshot

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!