@@ -190,7 +190,7 @@ export class JSONSchemaForm extends LitElement {
190190 }
191191
192192 base = [ ] ;
193- #nestedForms = { } ;
193+ forms = { } ;
194194 inputs = [ ] ;
195195
196196 tables = { } ;
@@ -268,7 +268,7 @@ export class JSONSchemaForm extends LitElement {
268268 const name = path [ 0 ] ;
269269 const updatedPath = path . slice ( 1 ) ;
270270
271- const form = this . #nestedForms [ name ] ; // Check forms
271+ const form = this . forms [ name ] ; // Check forms
272272 if ( ! form ) {
273273 const table = this . tables [ name ] ; // Check tables
274274 if ( table && tables ) return table ; // Skip table cells
@@ -363,7 +363,7 @@ export class JSONSchemaForm extends LitElement {
363363 status ;
364364 checkStatus = ( ) => {
365365 checkStatus . call ( this , this . #nWarnings, this . #nErrors, [
366- ...Object . entries ( this . #nestedForms )
366+ ...Object . entries ( this . forms )
367367 . filter ( ( [ k , v ] ) => {
368368 const accordion = this . #accordions[ k ] ;
369369 return ! accordion || ! accordion . disabled ;
@@ -382,7 +382,7 @@ export class JSONSchemaForm extends LitElement {
382382 return validator
383383 . validate ( resolved , schema )
384384 . errors . map ( ( e ) => {
385- const propName = e . path . slice ( - 1 ) [ 0 ] ?? name ?? e . property ;
385+ const propName = e . path . slice ( - 1 ) [ 0 ] ?? name ?? ( e . property === "instance" ? "Form" : e . property ) ;
386386 const rowName = e . path . slice ( - 2 ) [ 0 ] ;
387387
388388 const isRow = typeof rowName === "number" ;
@@ -391,6 +391,10 @@ export class JSONSchemaForm extends LitElement {
391391
392392 // ------------ Exclude Certain Errors ------------
393393
394+ // Allow for constructing types from object types
395+ if ( e . message . includes ( "is not of a type(s)" ) && "properties" in schema && schema . type === "string" )
396+ return ;
397+
394398 // Ignore required errors if value is empty
395399 if ( e . name === "required" && ! this . validateEmptyValues && ! ( e . property in e . instance ) ) return ;
396400
@@ -478,10 +482,10 @@ export class JSONSchemaForm extends LitElement {
478482 if ( message ) this . throw ( message ) ;
479483
480484 // Validate nested forms (skip disabled)
481- for ( let name in this . #nestedForms ) {
485+ for ( let name in this . forms ) {
482486 const accordion = this . #accordions[ name ] ;
483487 if ( ! accordion || ! accordion . disabled )
484- await this . #nestedForms [ name ] . validate ( resolved ? resolved [ name ] : undefined ) ; // Validate nested forms too
488+ await this . forms [ name ] . validate ( resolved ? resolved [ name ] : undefined ) ; // Validate nested forms too
485489 }
486490
487491 for ( let key in this . tables ) {
@@ -510,10 +514,16 @@ export class JSONSchemaForm extends LitElement {
510514 else {
511515 const level1 = acc ?. [ skipped . find ( ( str ) => acc [ str ] ) ] ;
512516 if ( level1 ) {
517+ // Handle items-like objects
518+ const result = this . #get( path . slice ( i ) , level1 , omitted , skipped ) ;
519+ if ( result ) return result ;
520+
521+ // Handle pattern properties objects
513522 const got = Object . keys ( level1 ) . find ( ( key ) => {
514523 const result = this . #get( path . slice ( i + 1 ) , level1 [ key ] , omitted , skipped ) ;
515- return result ;
524+ if ( result && typeof result === "object" ) return result ; // Schema are objects...
516525 } ) ;
526+
517527 if ( got ) return level1 [ got ] ;
518528 }
519529 }
@@ -550,7 +560,7 @@ export class JSONSchemaForm extends LitElement {
550560 }
551561
552562 // NOTE: Refs are now pre-resolved
553- const resolved = this . #get( path , schema , [ "properties" , "patternProperties" ] , [ "patternProperties" ] ) ;
563+ const resolved = this . #get( path , schema , [ "properties" , "patternProperties" ] , [ "patternProperties" , "items" ] ) ;
554564 // if (resolved?.["$ref"]) return this.getSchema(resolved["$ref"].split("/").slice(1)); // NOTE: This assumes reference to the root of the schema
555565
556566 return resolved ;
@@ -596,16 +606,6 @@ export class JSONSchemaForm extends LitElement {
596606 } ) ;
597607
598608 this . inputs [ localPath . join ( "-" ) ] = interactiveInput ;
599- // this.validateEmptyValues ? undefined : (el) => (el.value ?? el.checked) !== ""
600-
601- // const possibleInputs = Array.from(this.shadowRoot.querySelectorAll("jsonschema-input")).map(input => input.children)
602- // const inputs = possibleInputs.filter(el => el instanceof HTMLElement);
603- // const fileInputs = Array.from(this.shadowRoot.querySelectorAll("filesystem-selector") ?? []);
604- // const allInputs = [...inputs, ...fileInputs];
605- // const filtered = filter ? allInputs.filter(filter) : allInputs;
606- // filtered.forEach((input) => input.dispatchEvent(new Event("change")));
607-
608- // console.log(interactiveInput)
609609
610610 return html `
611611 < div id =${ encode ( localPath . join ( "-" ) ) } class ="form-section">
@@ -625,7 +625,7 @@ export class JSONSchemaForm extends LitElement {
625625 nLoaded = 0 ;
626626
627627 checkAllLoaded = ( ) => {
628- const expected = [ ...Object . keys ( this . #nestedForms ) , ...Object . keys ( this . tables ) ] . length ;
628+ const expected = [ ...Object . keys ( this . forms ) , ...Object . keys ( this . tables ) ] . length ;
629629 if ( this . nLoaded === expected ) {
630630 this . #loaded = true ;
631631 this . onLoaded ( ) ;
@@ -886,12 +886,10 @@ export class JSONSchemaForm extends LitElement {
886886
887887 // Validate Regex Pattern automatically
888888 else if ( schema . pattern ) {
889- const regex = new RegExp ( schema . pattern ) ;
889+ const regex = new RegExp ( schema . pattern , schema . flags ) ;
890890 if ( ! regex . test ( parent [ name ] ) ) {
891891 errors . push ( {
892- message : `${ schema . title ?? header ( name ) } does not match the required pattern (${
893- schema . pattern
894- } ).`,
892+ message : `${ schema . title ?? header ( name ) } does not match the required pattern (${ regex } ).` ,
895893 type : "error" ,
896894 } ) ;
897895 }
@@ -1105,7 +1103,7 @@ export class JSONSchemaForm extends LitElement {
11051103 const ignore = getIgnore ( this . ignore , name ) ;
11061104
11071105 const ogContext = this ;
1108- const nested = ( this . #nestedForms [ name ] = new JSONSchemaForm ( {
1106+ const nested = ( this . forms [ name ] = new JSONSchemaForm ( {
11091107 identifier : this . identifier ,
11101108 schema : info ,
11111109 results : { ...nestedResults } ,
@@ -1189,7 +1187,7 @@ export class JSONSchemaForm extends LitElement {
11891187 subtitle : html `< div style ="display:flex; align-items: center; ">
11901188 ${ explicitlyRequired ? "" : enableToggleContainer }
11911189 </ div > ` ,
1192- content : this . #nestedForms [ name ] ,
1190+ content : this . forms [ name ] ,
11931191
11941192 // States
11951193 open : oldStates ?. open ?? ! hasMany ,
@@ -1329,9 +1327,7 @@ export class JSONSchemaForm extends LitElement {
13291327 // Check if everything is internally rendered
13301328 get rendered ( ) {
13311329 const isRendered = resolve ( this . #rendered, ( ) =>
1332- Promise . all (
1333- [ ...Object . values ( this . #nestedForms) , ...Object . values ( this . tables ) ] . map ( ( { rendered } ) => rendered )
1334- )
1330+ Promise . all ( [ ...Object . values ( this . forms ) , ...Object . values ( this . tables ) ] . map ( ( { rendered } ) => rendered ) )
13351331 ) ;
13361332 return isRendered ;
13371333 }
0 commit comments