Avoid double-quotes in field error messages JS code

This commit is contained in:
Lance Edgar 2022-08-12 19:47:25 -05:00
parent d5a9aa6925
commit e49a31df6a

View file

@ -904,10 +904,19 @@ class Form(object):
# show errors if present # show errors if present
error_messages = self.get_error_messages(field) error_messages = self.get_error_messages(field)
if error_messages: if error_messages:
# TODO: this surely can't be what we ought to do
# here..? seems like we must pass JS but not JSON,
# sort of, so we custom-write the JS code to ensure
# single instead of double quotes delimit strings
# within the code.
message = '[{}]'.format(', '.join([
"'{}'".format(msg.replace("'", r"\'"))
for msg in error_messages]))
attrs.update({ attrs.update({
'type': 'is-danger', 'type': 'is-danger',
# ':message': self.messages_json(error_messages), ':message': message,
':message': error_messages,
}) })
# merge anything caller provided # merge anything caller provided