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

Text field type returns numbers #908

Closed
andrewn opened this issue Oct 30, 2018 · 3 comments
Closed

Text field type returns numbers #908

andrewn opened this issue Oct 30, 2018 · 3 comments

Comments

@andrewn
Copy link

andrewn commented Oct 30, 2018

Description of problem

Fields with the "text" type can sometimes return numbers in JSON, including leading zeroes being trimmed from the output.

This causes problems with:

  • fields where the leading zeros are important (e.g. if an external ID is being stored in the text field)
  • API consumers that expect all items to have the same type (e.g. Gatsby JS throws when it finds some numbers and some strings.

This seems to be the same bug as #283, but that has since been closed without a resolution that I can see.

Test schema

Here's the schema of a test collection with a single field of type text:

{
	"name": "test",
	"label": "",
	"_id": "test5bd86bcc4a0a7",
	"fields": [
		{
			"name": "textField",
			"label": "",
			"type": "text",
			"default": "",
			"info": "",
			"group": "",
			"localize": false,
			"options": [],
			"width": "1-1",
			"lst": true,
			"acl": [],
			"required": false
		}
	],
	"sortable": false,
	"in_menu": false,
	"_created": 1540910028,
	"_modified": 1540910122,
	"color": "",
	"acl": [],
	"rules": {
		"create": {
			"enabled": false
		},
		"read": {
			"enabled": false
		},
		"update": {
			"enabled": false
		},
		"delete": {
			"enabled": false
		}
	},
	"itemsCount": 4
}

Examples

I've added some test data to the collection:

  1. Saving an empty field outputs "" (empty JSON string)
  2. 01234 outputs 1234 (JSON number, leading zero missing)
  3. "01234" (with quotes) outputs "\"01234\"" (JSON string, with escaped quotes)

I'd expect example 2 to output the JSON string "01234".

{
	"fields": {
		"textField": {
			"name": "textField",
			"type": "text",
			"localize": false,
			"options": []
		}
	},
	"entries": [
		{
			"textField": "",
			"_mby": "5bd86b95633434001000004c",
			"_by": "5bd86b95633434001000004c",
			"_modified": 1540910129,
			"_created": 1540910129,
			"_id": "5bd86c3163343400110003ce"
		},
		{
			"textField": "\"01234\"",
			"_mby": "5bd86b95633434001000004c",
			"_by": "5bd86b95633434001000004c",
			"_modified": 1540910171,
			"_created": 1540910171,
			"_id": "5bd86c5b63343400160000fc"
		},
		{
			"textField": 1234,
			"_mby": "5bd86b95633434001000004c",
			"_by": "5bd86b95633434001000004c",
			"_modified": 1540910758,
			"_created": 1540910758,
			"_id": "5bd86ea6633434001d00036d"
		}
	],
	"total": 3
}
@raffaelj
Copy link
Contributor

Do you use MongoDB or SQLite?
Seems to be the same as #907 (created 5min before your issue)

@andrewn
Copy link
Author

andrewn commented Oct 30, 2018

I'm using SQLite.

@raffaelj
Copy link
Contributor

fixed here: 4a90575

Can be closed.

@aheinze aheinze closed this as completed Aug 10, 2019
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

3 participants