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

Fix number field template so it works within Collections. #3146

Merged
merged 1 commit into from
Mar 29, 2022

Conversation

dadaxr
Copy link
Contributor

@dadaxr dadaxr commented Mar 28, 2022

since v5.1.5, commit #3122 when number field "mode" is "float" (which is by default), the step is "'any'" by default (note the single quote wrapped by the double quote).
This "'any'" value should not be escaped because it breaks when the number field is used within a collection.

For instance, bellow is an extract of an "editor-collection" component generated by the backend when using a collection field having "number" field as child,
we can see it use a :template prop filled with escaped templates of fields members :

 <editor-collection
      :existing-fields='[]'
      :templates='[{ ..  &lt;editor-number  ...  value=\&quot;\&quot;\n    :step=\&quot;&amp;#039;any&amp;#039;\&quot;\n    ...'
      :labels='...'
      :limit='200'
      :name="&quot;gallery_slider_images&quot;"
      :variant="&quot;collapsed&quot;"
    ></editor-collection>

Without applying a |raw filter, the value is double encoded and generates :

:step=\&quot;&amp;#039;any&amp;#039;\&quot; (which decoded is the same as :step=\"&#039;any&#039;\"

instead of :step=\&quot;&#039;any&#039;\&quot; (which decoded is the same as :step=\"'any'\")

This leads to a vue compilation error :

[Vue warn]: Error compiling template:
 ...
<editor-number :id='&quot;field-gallery_slider_images-slider_image_set-6241de74820e3-coord_y&quot;' name="collections[gallery_slider_images][slider_image_set][6241de74820e3][coord_y]" value="" :step="&#039;any&#039;" :required="false" :readonly="false" :errormessage="false" :pattern="false" :placeholder="&quot;&quot;" ></editor-number>
...
- invalid expression: expected expression, got '&' in &#039;any&#039; Raw expression: :step="&#039;any&#039;"

However when using number field directly (ie without a collection field) it's was working.

Using the |raw filter makes it work in both cases.

Note : this regression can lead to data loss when saving broken collections ...

since v5.1.5, commit bolt#3122  when number field "mode" is "float" (which is by default), the step is "'any'" by default (note the single quote wrapped by the double quote).  
This "'any'" value should not be escaped because it breaks when the number field is used within a collection. 

For instance, bellow is an extract of an "editor-collection" component generated by the backend when using a collection field having "number" field as child,
we can see it use a :template prop filled with escaped templates of fields members : 
```
 <editor-collection
      :existing-fields='[]'
      :templates='[{ ..  &lt;editor-number  ...  value=\&quot;\&quot;\n    :step=\&quot;&amp;bolt#39;any&amp;bolt#39;\&quot;\n    ...'
      :labels='...'
      :limit='200'
      :name="&quot;gallery_slider_images&quot;"
      :variant="&quot;collapsed&quot;"
    ></editor-collection>
```

Without applying a |raw filter, the value is double encoded and generates :
 
`:step=\&quot;&amp;bolt#39;any&amp;bolt#39;\&quot;`  (which decoded is the same as `:step=\"&bolt#39;any&bolt#39;\"`

instead of `:step=\&quot;&bolt#39;any&bolt#39;\&quot;` (which decoded is the same as `:step=\"'any'\"`)

This leads to a vue compilation error : 

```
[Vue warn]: Error compiling template:
 ...
<editor-number :id='&quot;field-gallery_slider_images-slider_image_set-6241de74820e3-coord_y&quot;' name="collections[gallery_slider_images][slider_image_set][6241de74820e3][coord_y]" value="" :step="&bolt#39;any&bolt#39;" :required="false" :readonly="false" :errormessage="false" :pattern="false" :placeholder="&quot;&quot;" ></editor-number>
...
- invalid expression: expected expression, got '&' in &bolt#39;any&bolt#39; Raw expression: :step="&bolt#39;any&bolt#39;"
```

However when using number field directly (ie without a collection field) it's was working. 

Using the |raw filter makes it work in both cases.

Note : this regression can lead to data loss when saving broken collections ...
Copy link
Contributor

@Joossensei Joossensei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! First of all good catch. I chose to escape the value because Vue didn't accept 'any' as a literal value. That's why I escaped it using the single quotes.

@Joossensei Joossensei merged commit 77dcec6 into bolt:master Mar 29, 2022
@bobdenotter bobdenotter changed the title fix number field template so it works within a collection field. Fix number field template so it works within Collections. Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants