@@ -819,6 +819,7 @@ field[ns.ui('Choice').uri] = function (
819819 }
820820
821821 const multiSelect = kb . any ( form , ui ( 'multiselect' ) ) // Optional
822+ if ( multiSelect ) opts . multiSelect = true
822823
823824 let selector
824825 rhs . refresh = function ( ) {
@@ -863,7 +864,26 @@ field[ns.ui('Choice').uri] = function (
863864 selectedOptions = [ ]
864865 }
865866 if ( event . action === 'ADD_OPTION' ) {
866- selectedOptions . push ( event . value )
867+ const stringValue = event . value + ''
868+ if ( stringValue . includes ( 'Create new' ) ) {
869+ const newObject = newThing ( dataDoc )
870+ const is = [ ]
871+ is . push ( $rdf . st ( subject , property , kb . sym ( newObject ) , dataDoc ) )
872+ if ( uiFrom ) is . push ( $rdf . st ( newObject , ns . rdf ( 'type' ) , kb . sym ( uiFrom ) , dataDoc ) )
873+ if ( subForm ) {
874+ addSubFormChoice ( dom , rhs , { } , $rdf . sym ( newObject ) , subForm , dataDoc , function ( ok , body ) {
875+ if ( ok ) {
876+ kb . updater . update ( [ ] , is , function ( uri , success , errorBody ) {
877+ if ( ! success ) rhs . appendChild ( errorMessageBlock ( dom , 'Error updating select: ' + errorBody ) )
878+ } )
879+ selectedOptions . push ( newObject )
880+ if ( callbackFunction ) callbackFunction ( ok , { widget : 'select' , event : 'new' } )
881+ } else {
882+ rhs . appendChild ( errorMessageBlock ( dom , 'Error updating data in field of select: ' + body ) )
883+ }
884+ } )
885+ }
886+ } else selectedOptions . push ( event . value )
867887 }
868888 selector . update ( selectedOptions )
869889 } )
@@ -1865,8 +1885,8 @@ export function makeSelectForChoice (
18651885 kb ,
18661886 subject ,
18671887 predicate ,
1868- options . mintClass ,
1869- null ,
1888+ uiFrom ,
1889+ options . subForm ,
18701890 dataDoc ,
18711891 function ( ok , body ) {
18721892 if ( ! ok ) {
@@ -1898,7 +1918,7 @@ export function makeSelectForChoice (
18981918
18991919 log . info ( 'selectForOptions: data doc = ' + dataDoc )
19001920
1901- if ( select . currentURI && options . subForm ) {
1921+ if ( select . currentURI && options . subForm && ! options . multiSelect ) {
19021922 addSubFormChoice ( dom , container , { } , $rdf . sym ( select . currentURI ) , options . subForm , dataDoc , function ( ok , body ) {
19031923 if ( ok ) {
19041924 kb . updater . update ( [ ] , is , function ( uri , success , errorBody ) {
0 commit comments