Avoid double-quotes in field error messages JS code
This commit is contained in:
		
							parent
							
								
									d5a9aa6925
								
							
						
					
					
						commit
						e49a31df6a
					
				
					 1 changed files with 11 additions and 2 deletions
				
			
		|  | @ -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 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar