Possible to modify/format uesr-submitted data behind the scenes? #10598
Labels
[Feature] Extensibility
The ability to extend blocks or the editing experience
[Type] Plugin Interoperability
Incompatibilities between a specific plugin and the block editor. Close with workaround notes.
[Type] Question
Questions about the design or development of the editor.
Describe the bug
I tried looking this up but didn't come up with anything, so sorry if it's a repeat - please point me to the relevant threads and I'll take it from there. I'm trying to put together a block that will allow my clients to add floor plans inside the content stream. I've got some data I'm wanting to track, but starting small I'm just trying to get each field working before I move onto the next. I've got the name field working just fine, but already ran into what might be bug with the cost field. I want the user to be able to enter a plain number, while the system outputs the data in a monetary format. This is what I've got:
If I format the cost in the
onChangeCost()
function, I get NaN because it looks like GB simply appends any new digits entered into the field to the dataset currently saved, and trying to type "123,456" turns into "$1.00", "$1.001", "$1.0012", etc. Obviously this won't do. However, trying to format the output results in this:Obviously, the actual output is what I want. This also brings up the fact that it all appears to work just fine until I refresh the entire page - none of this validation or sanitizing is reflected in the actual UI.
To Reproduce
Create a custom block with the code above. Add '123456' to the 'cost' field, update the post, then refresh the page.
Expected behavior
I should see '$123,456.00' in the 'cost' field. I see 'NaN' and the warning that the block has been modified externally.
Desktop (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: