Convert values to symbols if necessary when creating the form #51

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Contributor

markrickert commented Nov 26, 2012

This one-liner allows external json files to be used instead of concrete ruby hashes in the code.

I needed to build the form based on some external JSON (either gathered from a server call or stored in the resources directory).

This now allows you to convert a JSON object to a hash and it will symbolize any elements that need to be converted for proper use.

Here's the example hash you use in the documentation, now working as a json object... note the hash symbols are strings that start with ":" such as "key": ":email"

formotion_data.json

{
  "sections": [{
    "title": "Register",
    "rows": [{
      "title": "Email",
      "key": ":email",
      "placeholder": "me@mail.com",
      "type": ":email",
      "auto_correction": ":no",
      "auto_capitalization": ":none"
    }, {
      "title": "Password",
      "key": ":password",
      "placeholder": "required",
      "type": ":string",
      "secure": true
    }, {
      "title": "Password",
      "subtitle": "Confirmation",
      "key": ":confirm",
      "placeholder": "required",
      "type": ":string",
      "secure": true
    }, {
      "title": "Remember?",
      "key": ":remember",
      "type": ":switch",
    }]
  }, {
    "title": "Account Type",
    "key": ":account_type",
    "select_one": true,
    "rows": [{
      "title": "Free",
      "key": ":free",
      "type": ":check",
    }, {
      "title": "Basic",
      "value": true,
      "key": ":basic",
      "type": ":check",
    }, {
      "title": "Pro",
      "key": ":pro",
      "type": ":check",
    }]
  }, {
    "rows": [{
      "title": "Sign Up",
      "type": ":submit",
    }]
  }]
}
Owner

clayallsopp commented Nov 26, 2012

Mmmm each of these settings that use a symbol should actually be type-agnostic by default. You should be able to use a regular string (ex type: "submit") with any of them without special formatting.

If that's causing problems, then that's a bug with that particular setting.

Contributor

markrickert commented Nov 26, 2012

Aha. You are correct. Sorry for wasting your time :(

Owner

clayallsopp commented Nov 26, 2012

No worries, definitely let me know if a String doesn't work for something (it hasn't been tested exhaustively, so something might go haywire)

Contributor

markrickert commented Nov 26, 2012

It appears to work correctly that way.

I was going to use formotion for a static tableview, but decided to implement it on my own since I needed infinite (theoretical) nesting in the json file. I'll be posting my example app to github tonight or tomorrow that shows how to use a proper nested json file to reuse the same view controller to drill down into child uitableviews.

Owner

clayallsopp commented Nov 26, 2012

Very cool, link me when it's up!

On Nov 26, 2012, at 2:20 PM, Mark Rickert notifications@github.com wrote:

It appears to work correctly that way.

I was going to use formotion for a static tableview, but decided to implement it on my own since I needed infinite (theoretical) nesting in the json file. I'll be posting my example app to github tonight or tomorrow that shows how to use a proper nested json file to reuse the same view controller to drill down into child uitableviews.


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment