jQuery.val on Dexteirty TextArea generates "Constrain not satisfied"

On Dexterity Type document, on a Textarea field, i'm using jQuery $(field).val() to assign its value from Mysql
This operation works fine.

But if the content assigned contains a newline /n or /r , the dexterity document cannot be saved and the error message "Constrain not satisfied" appears.

If instead of assigning its value from mysql via jquery i just simply copy/paste the same content (with /n and /r) on the UI , no error ocurs.

I suspect it's an issue with dexterity validation or more directly with mockup functionality.

I'm new at Plone related development .. I would appreciate any leads on where to look to solve this problem.

Thank's

zope.schema has special fields for a line of text and a general text. The value of a text line filed must not contain a line separator.

I assume that in your schema, the corresponding field is a text line field (and not a general text field).

1 Like

Thak you Dieter !
it is a text field, on chrome inspect one can see the textarea tag
line separators doesn't cause problems if they are inputted manually, but using jquery $(field).val(' text with line separators') does not met the validation requirements

I think you can set it with

 $( "#myfield" ).html( data );

(where data is 'your text with \n and \ r ' )

NOTE: (From what I remember) This approach is different with Textareas and other 'inputs', since other inputs does not keep newlines etc.

1 Like

I have looked at the Text field implementation in zope.schema._bootstrapfields.Text. A Constraint not satisfied error should occur only when the field has a constraint. By default, a Text field does not have an associated constraint.

Maybe, you debug the behaviour?

1 Like

Thank you Dieter and Espen ! The thing worked !
It was solved by:

  • Using $(#field).html('Content with \n')
  • Using the same for a hidden field i didn't take into account, indeed it wasn't only the Text field

Thank you both, best wishes
:+1: