{"action":"created","issue":{"url":"https://api.github.com/repos/google/blockly/issues/310","repository_url":"https://api.github.com/repos/google/blockly","labels_url":"https://api.github.com/repos/google/blockly/issues/310/labels{/name}","comments_url":"https://api.github.com/repos/google/blockly/issues/310/comments","events_url":"https://api.github.com/repos/google/blockly/issues/310/events","html_url":"https://github.com/google/blockly/issues/310","id":145350216,"number":310,"title":"New field_number type (and maybe others) for better <input> fields and standardized validators","user":{"login":"AnmAtAnm","id":9916202,"avatar_url":"https://avatars.githubusercontent.com/u/9916202?v=3","gravatar_id":"","url":"https://api.github.com/users/AnmAtAnm","html_url":"https://github.com/AnmAtAnm","followers_url":"https://api.github.com/users/AnmAtAnm/followers","following_url":"https://api.github.com/users/AnmAtAnm/following{/other_user}","gists_url":"https://api.github.com/users/AnmAtAnm/gists{/gist_id}","starred_url":"https://api.github.com/users/AnmAtAnm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AnmAtAnm/subscriptions","organizations_url":"https://api.github.com/users/AnmAtAnm/orgs","repos_url":"https://api.github.com/users/AnmAtAnm/repos","events_url":"https://api.github.com/users/AnmAtAnm/events{/privacy}","received_events_url":"https://api.github.com/users/AnmAtAnm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-04-02T08:14:43Z","updated_at":"2016-04-07T17:28:43Z","closed_at":null,"body":"Blockly needs a number field type, and possible more field types to expose `<input>` features, especially in a mobile environment where the appropriate type can lead to better input methods / onscreen keyboards.\r\n\r\nI propose `field_number`, with JSON attributes `value`, `precision`, `min` & `max`. A number must be divisible by `precision` (usually a power of 10), and inclusively between `min` and `max`.\r\n\r\n`field_integer` might be shorthand for a field_number with precision == 1.  `min` and `max` still apply.\r\n\r\n### Why?\r\n\r\nRight now, there there are only two ways to mark a field as a number:\r\n\r\n1. Use the undocumented input field validators, the way `math_number` does: `new Blockly.FieldTextInput('0', Blockly.FieldTextInput.numberValidator)`.\r\n2. Use the overly specific FieldAngleInput.\r\n\r\nBoth create `<input>` HTML for typing in the number, but neither input field uses `type=\"number\"` to trigger HTML level validation and appropriate input methods.  This is especially important on mobile, where numeric input are much more cumbersome on the full keyboard, compared to the number specific input method.  [Try it out.](http://jsfiddle.net/ctsobcdL/3/embedded/result/)\r\n\r\nFurther, the current use of functions as validators means these current features are inaccessible from JSON block definitions. With a new `field_number`, a validating and normalizing function could be generated with a small handful of optional parameters: min, max, precision, etc.\r\n\r\nFor example:\r\n\r\n    {\r\n      \"id\": \"math_decimal\",\r\n      \"message0\": \"%1\",\r\n      \"args0\": [\r\n        {\r\n          \"type\": \"field_number\",\r\n          \"name\": \"NUM\",\r\n          \"value\": 10.00\r\n        }\r\n      ],\r\n    },\r\n    {\r\n      \"id\": \"math_integer\",\r\n      \"message0\": \"%1\",\r\n      \"args0\": [\r\n        {\r\n          \"type\": \"field_number\",\r\n          \"name\": \"NUM\",\r\n          \"value\": 10,\r\n          \"precision\": 1\r\n        }\r\n      ],\r\n    }\r\n\r\nOr:\r\n\r\n    {\r\n      \"id\": \"midi_note\",\r\n      \"message0\": \"%1\",\r\n      \"args0\": [\r\n        {\r\n          \"type\": \"field_integer\",\r\n          \"name\": \"NOTE\",\r\n          \"value\": 60,\r\n          \"min\": 0,\r\n          \"max\": 127\r\n        }\r\n      ],\r\n    }\r\n\r\n### Further types\r\n\r\nWhile perhaps not quite as necessary for Blockly, there are other input types that provide improved desktop input and excellent mobile input methods: `\"date\"`, `\"time\"`, `\"week\"`, `\"month\"`, `\"tel\"`.  With lesser benefit, there is also `\"email\"` and `\"url\"` (though the CSS `:valid` and `:invalid` selectors can be useful).\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/google/blockly/issues/comments/207013646","html_url":"https://github.com/google/blockly/issues/310#issuecomment-207013646","issue_url":"https://api.github.com/repos/google/blockly/issues/310","id":207013646,"user":{"login":"pelikhan","id":4175913,"avatar_url":"https://avatars.githubusercontent.com/u/4175913?v=3","gravatar_id":"","url":"https://api.github.com/users/pelikhan","html_url":"https://github.com/pelikhan","followers_url":"https://api.github.com/users/pelikhan/followers","following_url":"https://api.github.com/users/pelikhan/following{/other_user}","gists_url":"https://api.github.com/users/pelikhan/gists{/gist_id}","starred_url":"https://api.github.com/users/pelikhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pelikhan/subscriptions","organizations_url":"https://api.github.com/users/pelikhan/orgs","repos_url":"https://api.github.com/users/pelikhan/repos","events_url":"https://api.github.com/users/pelikhan/events{/privacy}","received_events_url":"https://api.github.com/users/pelikhan/received_events","type":"User","site_admin":false},"created_at":"2016-04-07T17:28:42Z","updated_at":"2016-04-07T17:28:42Z","body":"Great!\n\nSent from Outlook Mobile<https://aka.ms/djubve>\n\n\n\n\nOn Thu, Apr 7, 2016 at 10:20 AM -0700, \"Andrew n marshall\" <notifications@github.com<mailto:notifications@github.com>> wrote:\n\n\n@pelikhan<https://github.com/pelikhan>\nErik's point was we have support for integers through precision: 1 (or 5, or 10 or 100, etc). So if a microcontroller only supports 32-bit ints, you could use:\n\n{\n  \"id\": \"math_int32\",\n  \"message0\": \"%1\",\n  \"args0\": [\n    {\n      \"type\": \"field_number\",\n      \"name\": \"NUM\",\n      \"value\": 10,\n      \"precision\": 1,\n      \"min\": -2147483648,\n      \"max\": 2147483647\n    }\n  ],\n}\n\n\n-\nYou are receiving this because you were mentioned.\nReply to this email directly or view it on GitHub<https://github.com/google/blockly/issues/310#issuecomment-207004922>\n"}}