apostrophecms / apostrophecms/apostrophe

3.0: Oembed field type can not be optional

Open
#3,261 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
4.6k
Forks
650
Avg merge
19h 21m
Merged PRs (30d)
23

Description

## To Reproduce
Imaginary oembed gallery widget:
```js
module.exports = {
extend: '@apostrophecms/widget-type',
options: {
label: 'Video gallery',
icon: 'video-icon'
},
fields: {
add: {
main: {
type: 'oembed',
name: 'main',
label: 'Main video URL (optional)',
oembedType: 'video'
},
// ...more fields
}
}
};
```
Once something is typed in the `main` field, it can not be deleted, as validation error 'video URL invalid' is preventing the save action of the widget. Additionally, if left empty (it's possible if nothing is typed), the `main` field will contain:
```json
{
"url": null,
"title": "",
"thumbnail": null
}
```
I'm not sure if it's intended, but just `null` sounds better in nunjucks environment because it is counter intuitive and would simplify an eventual template check - `if main` against `if main.url`

## Expected behavior
`oembed` field type should be allowed to be optional.

## Details
Apostrophe version: 3.0.1

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the optional `oembed` field behavior using the widget configuration shown in the issue and Apostrophe 3.0.1. Trace the field's validation and empty-value handling; done means an entered video URL can be cleared, the widget saves when the field is empty, and the empty value has the intended representation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.