1

How should I be getting values from a FormPanel using ext-react 6.6.0?

According to the API documentation I should be using getValues function, that works in 6.5.1 but I get error _this.form.getValues is not a function in 6.6.0

Code

Works in 6.5.1: https://fiddle.sencha.com/?extreact#view/editor&fiddle/2n05

Fails in 6.6.0 (see console for error): https://fiddle.sencha.com/?extreact#view/editor&fiddle/2n04

Alex Wachira
  • 1,225
  • 16
  • 19

1 Answers1

4

I get error _this.form.getValues is not a function in 6.6.0

The reason ref={form => this.form = form}. In extreact-6.6.0 the form variable is not exact formpanel. So for this you need to access like this

ref={form => this.form = (this.form || form.cmp)}}

Another way you use button.up('formpanel') to get the formpanel component. This button is first parameter of your handler.

button.up('formpanel').getValues()

You can check here with working fiddle.

Code Snippet

import React, { Component } from 'react';
import {launch} from '@sencha/ext-react';
import { ExtReact } from '@sencha/ext-react';
import { Container, Label, FormPanel, TextField, Button } from '@sencha/ext-modern';

class App extends Component {

    state = {
        values:JSON.stringify({
            fname: 'null',
            lname: 'null'
        })
    }

    submit = (btn) => {
        const values = btn.up('formpanel').getValues();

        console.log('Values using up selector',values);

        console.log('Values using up ref',this.form.getValues());

        this.setState({values:JSON.stringify(this.form.getValues())});
    }

    render() {
        return (
            <Container defaults={{ margin: 10, shadow: true }}>
                <FormPanel title="Form" ref={form => this.form = (this.form || form.cmp)}>
                    <TextField name="fname" label="First Name"/>
                    <TextField name="lname" label="Last Name"/>
                    <Button handler={this.submit} text="Submit"/>
                </FormPanel>

                <Label padding={'10'} html={this.state.values} />
            </Container>
        )
    }
}

launch(<ExtReact><App /></ExtReact>);
Narendra Jadhav
  • 10,052
  • 15
  • 33
  • 44