Comments (8)
Hello,
Great idea. I think we should use:
- 'type' attribute (if it's 'number', 'date' etc) - for simplicity
- 'data-type' if 'type' attribute is absent (like in selects) or
value type cannot be figured out of 'type' attribute (like in hiddens,
radios, checkboxes).
This conforms HTML5 standard and most browsers (IE6+ too) can use it
(via getAttribute() or getAttributeNode() methods).
from form2js.
"data-type" seems nice! I read some texts about adding custom attributes to HTML elements and I started using them on my framework project (on a different context). Using data-* is working fine for me. It doesn't interfere with existing attributes and should be officially supported in the near future.
I believe using always "data-type" (instead of sometimes "type") would be the best choice. type="number" renders differently on Firefox and Chrome. On Firefox (9, at least), it's the same as type="text". On Chrome, it displays up/down arrows so you can increment/decrement the number - not necessarily what the developer wants. The developer might not want to add HTML5 features to his/her site, and this would force him/her to do so.
It seems to me that using only "data-type" would be simpler, and also more consistent among all input types. The developer would still have the option of adding type="number" or "date" if he/she wants to, and this would not interfere on form2js.
What do you think?
from form2js.
I think "type" attribute should be considered also. We should figure data type from markup if we can, but probably, "data-type" attribute should have higher precendence than "type" (for more consistent interface).
from form2js.
I agree with you. If data-type has higher precedence, the interface will surely be consistent enough :).
I thought about the type="date" thing you mentioned. The Date type exists only on JS, not on JSON. So, if one is using form2js to convert forms to JSON (instead of pure JavaScript objects), he/she might want to use some custom function to convert from date to string. So, maybe it would be nice also if it's made possible to do something like data-type="customBla" or something, which would then call the function customBla() to convert from the field string value to whatever the user likes. I know it's already possible to do something like that by passing arguments when calling the form2js function, but maybe it would be nicer if one could express that directly on the input element.
Maybe some convetion would make it fine, like that "custom" thing. This one doesn't seem quite good, but anyway it's just an example.
What do you think?
from form2js.
Great idea! I think we should also add a 'custom attribute' parameter
and check for all elements with such attribute on deserialization.
from form2js.
I bumped on this issue as I was wondering if form2js would support with data types.
I wonder what the status is of this issue and implementing it.
One thing I would to add is also the discussion of number formatting.
E.g I develop a Dutch site and there users will enter 12,95 for 12 euros and 95 cents. Note the , as decimal separator instead of . .
from form2js.
Also would like to know the status of this issue since it is quite important for real production env ...
Thanks!
from form2js.
My solution:
switch (value)
{
case 'null': value = null; break;
case 'true': value = true; break;
case 'false': value = false;
}
if (!isNaN(parseFloat(value)) && isFinite(value)) value = parseFloat(value);
Insert this code after line 93.
Realizes types of null, true, false, integer and float.
from form2js.
Related Issues (20)
- Support multiple files ?
- A way to create an empty list when no checkboxes are selected. HOT 2
- js2form modifies SELECT element with disabled first option when property in JSON doesn't exist
- version tags not working
- js2form: subObjects having a one-char-length don't work
- [enhancement] Add missing bower.json. HOT 1
- Same as https://github.com/marioizquierdo/jquery.serializeJSON HOT 7
- Ability to exclude a node in nodeCallback HOT 1
- Radio button true and false value bug HOT 1
- Is there a way to get disabled fields
- get the input value inside innerhtml
- how to capture the select options value and text
- N-Number of depth
- JSON Output format
- js2form: bind list of values to multiselect
- unknown error: rootNode is null
- js2form don't feed any value
- what file? HOT 1
- Get false value for checkbox HOT 1
- Некорректная работа HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from form2js.