Skip to content

Checkbox in form error #558

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

Closed
JonFir opened this issue Sep 28, 2015 · 13 comments
Closed

Checkbox in form error #558

JonFir opened this issue Sep 28, 2015 · 13 comments

Comments

@JonFir
Copy link

JonFir commented Sep 28, 2015

Hello!
I try add checkbox to form

{
    "key": "modules.bindadm",
    "type": "checkbox",
    "value": "dsadsa",
    "title": "Будет установлен модуль управления почтовым сервером"
}

and take error Error: undefined is not an object (evaluating 'obj.schema['default'])'

I inspect source code, and find this section:

if (obj.type === 'checkbox' && angular.isUndefined(obj.schema['default'])) {
   obj.schema['default'] = false;
}

You try determinate obj.schema['default'], but obj not have property schema:

[Log] Object (schema-form.js, line 1463)
key: Array[2]
title: "Будет установлен модуль управления почтовым сервером"
type: "checkbox"
value: "dsadsa"
__proto__: Object

My js skill very low) but i try change you code like:

if (obj.type === 'checkbox' && angular.isUndefined(obj.schema)) {
    obj.schema = ['default'];
    obj.schema['default'] = false;
}

This code work, but i don't know, may be its bad solution.

And i have answer question. Can i add value to checkbox. In default, checkbox can be true or false, but i need, add string value, like 'some string', its possible?
P.S.: Sorry my low english skill.
Regards.

@vinceis1337
Copy link

@davidlgj can you or someone else take a look at this? I'm having the same issue:
screen shot 2015-11-12 at 8 20 50 pm

Which is definitely from this code.

@sgarbesi
Copy link

sgarbesi commented Mar 8, 2016

+1

@Anthropic
Copy link
Member

@JonFir @vinceis1337 @sgarbesi if anyone can put together a gist/plunker/demo that would be a great help?

@vinceis1337
Copy link

@Anthropic I don't remember how exactly I got this problem but I can tell you why it is happening.

The issue is that obj.schema ITSELF is undefined, my guess is because we self-define the checkbox (inside of $scope.form) instead of generating it from a schema.

This means that inherently, the checkbox has no reference data from the schema, therefore it logically has no schema property.

Therefore, the check angular.isUndefined(obj.schema['default'])) fails as it is attempting to read a child property when the parent does not exist.

I believe the proper fix is to first check whether obj.schema exists as follows:

//check if object is a checkbox
if (obj.type === 'checkbox') {
  //check if obj has a schema
  if (angular.isUndefined(obj.schema) {
    //if it doesn't, add a schema definition that consists only of a default state of false
    obj.schema = { default: false };
  }
  //if object has a schema, check if the default state is defined
  else if (angular.isUndefined(obj.schema['default'])) {
    //if it is not defined, define it as false
    obj.schema['default'] = false;
  }
}

Please note that this logic occurs in two places: src/services/schema-form.js and dist/schema-form.js. I don't know if they are synchronized but you may have to change it in both places.

Search results here.

This gist:
http://schemaform.io/examples/bootstrap-example.html#/b24a68ddb628dc2cfcdccf42b95f5725

Demonstrates how the bug halts the creation of the form when reaching this logic.

@Anthropic Anthropic added this to the Backlog milestone Apr 11, 2016
@Anthropic
Copy link
Member

@vinceis1337 the dist folder is the built files, so that is fine.

What happens if you have a default value on the form definition, is that not enough to avoid the issue?

@vinceis1337
Copy link

@Anthropic I am not sure what you mean.

If you mean setting value to true or false, it doesn't appear to fix the issue.
Gist: http://schemaform.io/examples/bootstrap-example.html#/69195a23f9eab268bcc2208cdbae22b4

If you mean setting a default key, that doesn't appear to be defined in the documentation. Also it doesn't work either.
Gist: http://schemaform.io/examples/bootstrap-example.html#/ee581d1abd7a47d76745798041758d0d

@Anthropic
Copy link
Member

Thanks @vinceis1337 appreciate your help, will need to re-visit this once the new core is split out from this repo to json-schema-form-core. Unless you are in a position to do a PR soon?

@vinceis1337
Copy link

@Anthropic sure, I can make a pull request. I'll need 10 minutes.

@Anthropic
Copy link
Member

@vinceis1337 that's awesome, the usual response to that question is "maybe next week". Just remember not to commit the dist folder please, and don't be concerned by the tests failing on four items, been meaning to fix them since I updated the CI tool since the repo changed location :)

@vinceis1337
Copy link

@Anthropic Glad to help! Angular Schema Form has been really helpful for me so I don't mind at all :).

And I was about to ask if I should gulp before submitting the PR, but that answers the question. :P

@Anthropic
Copy link
Member

There is a CONTRIBUTING md ;)

@vinceis1337
Copy link

Ooo I see that now. Thanks!

#663 created.

@Anthropic
Copy link
Member

@vinceis1337 if you want to contribute, we are always looking for people to help, the Gitter is a good source for seeing where and when help is needed as we begin the next phase of the project since Textalk gave it up to the internets leading up to v1 :)

Closing this now as discussion can move to PR.

@Anthropic Anthropic modified the milestones: 0.9.0, Backlog Apr 11, 2016
@Anthropic Anthropic removed this from the 0.9.0 milestone Feb 27, 2017
@Anthropic Anthropic modified the milestones: 1.0.0, 0.9.0 Feb 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants