Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clearing form field #12

Closed
danielc103 opened this issue Nov 18, 2018 · 5 comments
Closed

Clearing form field #12

danielc103 opened this issue Nov 18, 2018 · 5 comments

Comments

@danielc103
Copy link

Clearing form field doesn't trigger onChanged so if setting a value there it sticks. Should onChanged be triggered for clearing form field or is there another way to clear value?

@jifalops
Copy link
Owner

jifalops commented Nov 25, 2018

Clearing the field, by pressing the "X" icon, does trigger onChange when I test it. Can you give steps to reproduce? I've also tried specifying its controller and calling controller.clear(), which seems to work as well.

@jifalops jifalops added the invalid This doesn't seem right label Nov 25, 2018
@danielc103
Copy link
Author

I've not specified a controller but will try that next.

After further investigation this doesn't seem to reveal itself on Android, only on iOS. Entering a date triggers, changing a date triggers, but clearing with the "X" button after does not.

Widget buildDatePicker() {
    Widget dp = Container(
      padding: EdgeInsets.fromLTRB(0, 50.0, 0, 0),
      child: Row(
        children: <Widget>[
          new Flexible(
              child: DateTimePickerFormField(
            editable: false,
            lastDate: DateTime(DateTime.now().year, DateTime.now().month,
                DateTime.now().day, DateTime.now().hour + 2),
            format: dateFormat,
            dateOnly: true,
            decoration: InputDecoration(
                prefixIcon: Icon(FontAwesomeIcons.calendar),
                labelText: 'Date',
                border: OutlineInputBorder(
                    borderSide: BorderSide(color: Colors.black))),
            onChanged: (dt) {
              print(dt);
              if (dt != null) {
                dateRoch = dt.millisecondsSinceEpoch;
              }
            },
          )),
        ],
      ),
    );

    return dp;
  }

@jifalops jifalops removed the invalid This doesn't seem right label Nov 27, 2018
@jifalops
Copy link
Owner

From looking at the relevant lines, I am guessing maybe iOS doesn't allow onChange to be called if the input isn't focused?

@chadidi
Copy link

chadidi commented Dec 7, 2018

you can user a controller instead (didn't test it yet with this plugin)

// create variable
TextEditingController date= new TextEditingController();
// assign varibale to controller
controller: date,
// access the value
date.text

@danielc103
Copy link
Author

I'll try the controller when I get a chance. I'll close this issue if all is working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants