question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to update form data after click event custom “Button” control?

See original GitHub issue

I created new custom control like button and after every click I need to update value of this control

import ButtonComponent from 'formiojs/components/button/Button.js';

export default class DynamicButton extends ButtonComponent {
  ...
  build() {
    this.dataValue = '';
    ...
    this.addEventListener(this.buttonElement, 'click', (event) => {
      this.dataValue = "some data";
    });
  }
  ...
}

So, value is updated and if I print console.log(this.data) here it’s also updated, but it doesn’t trigger “change” event on form and when I submit form then data for this control doesn’t exist.

What I need to execute to trigger “change” event on form and populate data of this control to form?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
gladkiycommented, Jan 17, 2019

I did the following:

build() {
    this.dataValue = '';
    ...
    this.addEventListener(this.buttonElement, 'click', (event) => {
      this.dataValue = "some data";
      this.triggerChange();
      console.log(this.dataValue);
      console.log(this.data);
    });
    ...
  }

But this.data = { "userName": "some data" } and this.dataValue = undefined. Why does this happen? Maybe because I inherit my control from “Button” that has just true or false value and this control overwrites value somehow?

I also have:

getValue() {
  return this.dataValue;
}

set dataValue(value) {
  super.dataValue = value;
}

How can I populate this.dataValue?

0reactions
gladkiycommented, Jan 21, 2019

I resolved that issue. I just inherit my custom control from TextFieldComponent.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add event to custom control that fired when click a ...
this in the click method on each button do something like this: public void Button1_Click(object sender, EventArgs e) { if (OnButton1Click ...
Read more >
Adding a custom button on a form widget - ServiceNow
I'm trying to add a custom button (called submit) on a form widget . When I click the button , it doesn't look...
Read more >
Assign a macro to a Form or a Control button - Microsoft Support
Add a button (Form control). On the Developer tab, in the Controls group, click Insert, and then under Form Controls, click Button Button...
Read more >
How to build custom form controls - Learn web development
For example, all four arrows navigate through the options, but clicking the down arrow when the user is on the last button takes...
Read more >
SharePoint 2013 - Custom save button - Handling click using ...
For example, on the "click" event of our custom button, we need to assign values based of values entered by the user. So...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found