Merge pull request #8 from usetrmnl/option-key-boolean-quotes

Fixes Issue #7
This commit is contained in:
Mario Lurig
2025-12-22 12:10:54 -07:00
committed by GitHub
2 changed files with 26 additions and 2 deletions
+22
View File
@@ -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', () => {
+4 -2
View File
@@ -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)}`);