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

[QUESTION] - Using component methods from within onSubmit #51

Closed
go4cas opened this issue Mar 15, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@go4cas
Copy link

commented Mar 15, 2019

How would I call a method defined on the component in the onSubmit? Currently this.add(formData) does not work.

@xaboy

This comment has been minimized.

Copy link
Owner

commented Mar 15, 2019

Sorry,I didn't understand what you mean. You can manually submit the form via $f.submit. When the form is verified, the onSubmit method can be triggered.

@go4cas

This comment has been minimized.

Copy link
Author

commented Mar 15, 2019

@xaboy, in my component file, I have a method add, which I use to update the entity to the API. I would like to call this method from within onSubmit.

export default {
  name: 'BrandList',
  mounted: async function () {
    this.model = this.fApi.model()
  },
  methods: {
    add(entity) {
      // call API to insert
    }
  },
  data () {
    return {
      fApi: {},
      model: {},
      option: {
        onSubmit: function (formData) {
          this.add(formData)
        }
      },
@xaboy

This comment has been minimized.

Copy link
Owner

commented Mar 15, 2019

export default {
  name: 'BrandList',
  mounted: async function () {
    this.model = this.fApi.model()
  },
  methods: {
    add(entity) {
      // call API to insert
    }
  },
  data () {
    const vm = this
    return {
      fApi: {},
      model: {},
      option: {
        onSubmit: function (formData) {
          vm.add(formData)
        }
      },
@go4cas

This comment has been minimized.

Copy link
Author

commented Mar 15, 2019

@xaboy , great thanks!

Another question: I see you use $f throughout your docs and examples. But, I can't find where or how to define $f.

@xaboy

This comment has been minimized.

Copy link
Owner

commented Mar 15, 2019

$f is the instance object returned by form-create,you can refer to here
http://form-create.com/en/guide/instance.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.