How to use the enketo-core/src/js/form-model.FormModel function in enketo-core

To help you get started, we’ve selected a few enketo-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kobotoolbox / enketo-express / public / js / src / enketo-webform.js View on Github external
function _prepareInstance( modelStr, defaults ) {
    let model;
    let init;
    let existingInstance = null;

    for ( const path in defaults ) {
        if ( Object.prototype.hasOwnProperty.call( defaults, path ) ) {
            model = model || new FormModel( modelStr, {
                full: false
            } );
            init = init || model.init();
            if ( Object.prototype.hasOwnProperty.call( defaults, path ) ) {
                // if this fails, the FormModel will output a console error and ignore the instruction
                model.node( path ).setVal( defaults[ path ] );
            }
            // TODO would be good to not include nodes that weren't in the defaults parameter
            // HOWEVER, that would also set number of repeats to 0, which may be undesired
            // TODO would be good to just pass model along instead of converting to string first
            existingInstance = model.getStr();
        }
    }
    return existingInstance;
}