@@ -29,6 +29,7 @@ export class AbstractEditor {
29
29
30
30
this . link_watchers = [ ]
31
31
this . watchLoop = false
32
+ this . optInWidget = this . options . opt_in_widget ?? this . jsoneditor . options . opt_in_widget
32
33
33
34
if ( options . container ) this . setContainer ( options . container )
34
35
this . registerDependencies ( )
@@ -216,16 +217,17 @@ export class AbstractEditor {
216
217
this . container . setAttribute ( 'data-schemapath' , this . path )
217
218
}
218
219
219
- setOptInCheckbox ( header ) {
220
- /* the active/deactive checbox control. */
220
+ setOptInCheckbox ( ) {
221
+ let optIn
221
222
222
- this . optInLabel = this . theme . getHiddenLabel ( this . formname + ' opt-in' )
223
- this . optInLabel . setAttribute ( 'for' , this . formname + '-opt-in' )
224
- this . optInCheckbox = document . createElement ( 'input' )
225
- this . optInCheckbox . setAttribute ( 'type' , 'checkbox' )
226
- this . optInCheckbox . setAttribute ( 'style' , 'margin: 0 10px 0 0;' )
227
- this . optInCheckbox . setAttribute ( 'id' , this . formname + '-opt-in' )
228
- this . optInCheckbox . classList . add ( 'json-editor-opt-in' )
223
+ if ( this . optInWidget === 'switch' ) {
224
+ optIn = this . theme . getOptInSwitch ( this . formname )
225
+ } else {
226
+ optIn = this . theme . getOptInCheckbox ( this . formname )
227
+ }
228
+
229
+ this . optInCheckbox = optIn . checkbox
230
+ this . optInContainer = optIn . container
229
231
230
232
this . optInCheckbox . addEventListener ( 'click' , ( ) => {
231
233
if ( this . isActive ( ) ) {
@@ -240,12 +242,12 @@ export class AbstractEditor {
240
242
const parentOptInDefined = ( typeof this . parent . options . show_opt_in !== 'undefined' )
241
243
const parentOptInEnabled = ( parentOptInDefined && this . parent . options . show_opt_in === true )
242
244
const parentOptInDisabled = ( parentOptInDefined && this . parent . options . show_opt_in === false )
245
+
243
246
if ( parentOptInEnabled || ( ! parentOptInDisabled && globalOptIn ) || ( ! parentOptInDefined && globalOptIn ) ) {
244
247
/* and control to type object editors if they are not required */
245
248
if ( this . parent && this . parent . schema . type === 'object' && ! this . isRequired ( ) && this . header ) {
246
- this . header . appendChild ( this . optInLabel )
247
- this . header . appendChild ( this . optInCheckbox )
248
- this . header . insertBefore ( this . optInCheckbox , this . header . firstChild )
249
+ this . header . insertBefore ( this . optInContainer , this . header . firstChild )
250
+ this . optInAppended = true
249
251
}
250
252
}
251
253
}
0 commit comments