0

I'm trying to extract the values of a Select field, from a JSON file that houses the translations. The problem is caused by the get_locale() function, which can only be called within 'context.'

This is the form select-field:

brand = SelectField(choices=generate_brands(get_locale()),validators=[Optional()])

is there a way to load this specific field only when called inside of a view when the request variable is available?

abood bah
  • 154
  • 3
  • 17

1 Answers1

1

If I well understood, you want to populate the SelectField depending of the language of the user. There are several ways to have dynamic SelectField, see Oleg's answer for a good example: https://stackoverflow.com/a/48236887/11405279

JBLaf
  • 776
  • 5
  • 10
  • Creating a request context does not solve the problem here, as in that case, the get_locale() function will return None meaning it will return the default locale. – abood bah Jun 23 '20 at 17:11
  • do you know of a way to lazyload a single field or the whole form if the former is not available? @JBLaf – abood bah Jun 23 '20 at 17:46
  • 1
    I changed my answer, as I first misunderstood what was wanted. Some good keywords to google what you want are: dynamic SelectField – JBLaf Jun 23 '20 at 18:19