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

[magic] Repeated keys error #282

Open
davidstackio opened this issue Aug 8, 2015 · 2 comments
Open

[magic] Repeated keys error #282

davidstackio opened this issue Aug 8, 2015 · 2 comments

Comments

@davidstackio
Copy link

When using magic to create forms, I have a repeated key property stock_keys.

On the form I have multiple checkboxes that look like this:

<input type="checkbox" name="stock_keys" value="ag1kZXZ-cG9ldC1wb2VtchILEgVTdG9jaxiAgICAgIi2Cww">

When submitting the form, this is the error I get:

BadValueError: Expected list or tuple, got Key('Stock', 4626195173867520)

Using version 3.2.3

@davidstackio
Copy link
Author

I have resolved the error by using model_form from my own fork of wtforms-appengine and my own custom multiple_key_checkbox_field html macro in macro/forms.html script:

# macro key_checkbox_field(field)
  <div class="form-group {{'has-error' if field.errors}}">
    {{field.label(class='control-label')}}
    {{field_optional(field)}}
    {{field_description(field)}}
    # for key, value in field.choices
      <div class="checkbox">
        <label>
          <input type="checkbox" name="{{field.name}}" value="{{key.id() if key else ''}}"
            # if field.data and (key == field.data or key in field.data)
              checked
            # endif
          > {{value}}
        </label>
      </div>
    # endfor
    {{field_errors(field)}}
  </div>
# endmacro

# macro multiple_key_checkbox_field(field)
  {{key_checkbox_field(field)}}
# endmacro

Using the above, the checkboxes on the forms look like this:

<input type="checkbox" name="stock_keys" value="6430218877140992">

I am more than happy to create a PR to add this functionality to the core of gae-init, but I'm not sure how to update the magic.

@trickidicki
Copy link

trickidicki commented Aug 16, 2017

Still an issue...
Would love to use 'repeating' KeyProperty fields so I can have multiple children of the same type (select using a dropdown or create on the fly) but at the moment getting
BadValueError: Expected list or tuple, got Key('Dimension', 4889528208719872)

@lipis lipis transferred this issue from gae-init/gae-init Aug 1, 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

2 participants