mirror of
https://github.com/usetrmnl/trmnl-form-builder.git
synced 2026-04-29 13:43:54 -07:00
Merge pull request #8 from usetrmnl/option-key-boolean-quotes
Fixes Issue #7
This commit is contained in:
@@ -214,6 +214,28 @@ describe('TRMNL Form Builder - YAML Operations', () => {
|
||||
|
||||
expect(yaml).toBe('# No fields defined yet')
|
||||
})
|
||||
|
||||
it('should quote boolean literal labels in options', () => {
|
||||
element.fields = [{
|
||||
id: 'field_1',
|
||||
keyname: 'show_email',
|
||||
field_type: 'select',
|
||||
name: 'Show Email',
|
||||
options: [
|
||||
{ 'Yes': 'yes' },
|
||||
{ 'No': 'no' },
|
||||
{ 'True': 'true' },
|
||||
{ 'False': 'false' }
|
||||
]
|
||||
}]
|
||||
|
||||
const yaml = element.generateYaml()
|
||||
|
||||
expect(yaml).toContain('"Yes": "yes"')
|
||||
expect(yaml).toContain('"No": "no"')
|
||||
expect(yaml).toContain('"True": "true"')
|
||||
expect(yaml).toContain('"False": "false"')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Helper Methods', () => {
|
||||
|
||||
@@ -1658,8 +1658,10 @@ class TRMLYamlForm extends HTMLElement {
|
||||
if (typeof opt === 'object') {
|
||||
// Label:Value pair - format as YAML key:value
|
||||
const [label, value] = Object.entries(opt)[0];
|
||||
// Don't escape the label in the key position, only the value
|
||||
lines.push(` - ${label}: ${this.escapeYaml(value)}`);
|
||||
// Escape both label and value to handle boolean literals
|
||||
const escapedLabel = this.escapeYaml(label);
|
||||
const escapedValue = this.escapeYaml(value);
|
||||
lines.push(` - ${escapedLabel}: ${escapedValue}`);
|
||||
} else {
|
||||
// Simple string
|
||||
lines.push(` - ${this.escapeYaml(opt)}`);
|
||||
|
||||
Reference in New Issue
Block a user