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

Uncaught TypeError: e.replace is not a function #377

Closed
travist opened this issue Mar 31, 2018 · 9 comments
Closed

Uncaught TypeError: e.replace is not a function #377

travist opened this issue Mar 31, 2018 · 9 comments

Comments

@travist
Copy link
Contributor

travist commented Mar 31, 2018

There is an issue with the latest 3.0.4 branch that was caused by this commit.

394bde3

The issue is that when I have select items that are objects, this fails with the following error.

Uncaught TypeError: e.replace is not a function
    at t.stripHTML (formio.full.js:16252)
    at Object.addItemText (formio.full.js:16250)
    at e.value (formio.full.js:16250)
    at e.value (formio.full.js:16250)
    at e.value (formio.full.js:16250)

It seems pretty clear that this was written for the select options that are strings, but did not take into account the select options that are objects where replace is not a function.

@travist
Copy link
Contributor Author

travist commented Mar 31, 2018

Fixed by #378

@travist
Copy link
Contributor Author

travist commented Apr 2, 2018

Here is a JSFiddle with the issue.

https://jsfiddle.net/travistidwell/1actk0fa/

@jshjohnson
Copy link
Collaborator

jshjohnson commented Apr 3, 2018

I think a cleaner solution would be to just cast value to a string within getWidthOfInput before running stripHTML. Then replace will always be defined.

@travist
Copy link
Contributor Author

travist commented Apr 3, 2018

I added a comment to the pull request that I would appreciate you reading and providing your input. One thing that I remembered when configuring this element is that you do allow for a "label" and a "value". Why are we not determining the width based on the "label" and not the "value". Maybe that would be cleaner since in every case the "label" will always be a string. That is something that is consistent no matter the type of value.

@jshjohnson
Copy link
Collaborator

getWidthOfInput is called when you are inputting data into the input field - this wouldn't be a label, it would be the actual value of the input 👍

@andershagbard
Copy link

andershagbard commented Jul 31, 2018

While waiting for an update for this package, you can add a dirty hotfix to your project.
Add a prototype function for Number and Object types.

Number.prototype.replace = function() {
    return this;
};

Object.prototype.replace = function() {
  return this;
};

@stale
Copy link

stale bot commented Oct 27, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 27, 2018
@TylerVigario
Copy link

Hopefully, this issue can be resolved soon...

@stale stale bot removed the stale label Oct 31, 2018
@stale stale bot added the stale label Dec 30, 2018
@Choices-js Choices-js deleted a comment from stale bot Dec 30, 2018
@stale stale bot removed the stale label Dec 30, 2018
@jshjohnson
Copy link
Collaborator

This has been fixed in version 6.0.2

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

4 participants