Skip to content

Commit

Permalink
submit and bindValue alias for import and export
Browse files Browse the repository at this point in the history
  • Loading branch information
ATHULKNAIR committed Dec 30, 2024
1 parent 5a6c758 commit cce07f7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 9 deletions.
61 changes: 54 additions & 7 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,64 @@
<script>
document.addEventListener('DOMContentLoaded', () => {
console.log('onload');
const form = document.getElementById("form1");
form.addEventListener("mb-submit", (e) => {
const form = document.getElementById('form1');
form.addEventListener('mb-submit', e => {
e.preventDefault();
console.log(e.detail)
})
console.log(e.detail);
});
});
</script>

<body>
<div style="max-width: 700px;">
<mb-form
<div style="max-width: 700px">
<mb-form id="form1">
<mb-context path="vital_signs.v0/context/start_time"></mb-context>
<mb-context path="vital_signs.v0/context/setting"></mb-context>

<mb-quantity
default="/min"
path="vital_signs.v0/pulse_heart_beat/any_event:0/rate"
label="Rate"
>
<mb-unit unit="/min" label="/min" min="" max="1000"></mb-unit>
</mb-quantity>
<mb-context
path="vital_signs.v0/pulse_heart_beat/any_event:0/time"
></mb-context>
<mb-context
path="vital_signs.v0/pulse_heart_beat/language"
></mb-context>
<mb-context
path="vital_signs.v0/pulse_heart_beat/encoding"
></mb-context>
<mb-context path="vital_signs.v0/pulse_heart_beat/subject"></mb-context>
<div class="blood-pressure-container">
<mb-quantity
default="mm[Hg]"
path="vital_signs.v0/blood_pressure/systolic"
label="Systolic"
>
<mb-unit unit="mm[Hg]" label="mm[Hg]" min="" max="1000"></mb-unit>
</mb-quantity>
<mb-quantity
default="mm[Hg]"
path="vital_signs.v0/blood_pressure/diastolic"
label="Diastolic"
>
<mb-unit unit="mm[Hg]" label="mm[Hg]" min="" max="1000"></mb-unit>
</mb-quantity>
</div>
<mb-input path="vital_signs.v0/blood_pressure/time/value" />
<mb-context path="vital_signs.v0/blood_pressure/time"></mb-context>
<mb-context path="vital_signs.v0/blood_pressure/language"></mb-context>
<mb-context path="vital_signs.v0/blood_pressure/encoding"></mb-context>
<mb-context path="vital_signs.v0/blood_pressure/subject"></mb-context>
<mb-context path="vital_signs.v0/category"></mb-context>
<mb-context path="vital_signs.v0/language"></mb-context>
<mb-context path="vital_signs.v0/territory"></mb-context>
<mb-context path="vital_signs.v0/composer"></mb-context>
</mb-form>
<!-- <mb-form
id="form1"
style="display: flex; gap:15px; flex-direction: column"
templateid="testing_template.v0"
Expand Down Expand Up @@ -66,7 +113,7 @@
<sl-button>Save</sl-button>
</mb-submit>
</div>
</mb-form>
</mb-form> -->
</div>
<div>
<pre></pre>
Expand Down
9 changes: 8 additions & 1 deletion src/medblocks/form/autoForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export class MedblocksAutoForm extends LitElement {
}

import(composition: MBComposition) {
this.bindValue(composition);
}

bindValue(composition: MBComposition) {
const mbForm = this.renderRoot.querySelector('mb-form') as MedblockForm;
mbForm.data = {};
const container = mbForm.querySelector('#autoForm') as Element;
Expand All @@ -132,8 +136,11 @@ export class MedblocksAutoForm extends LitElement {
}, 10);
}

// Method to get form value
export() {
return this.submit();
}

submit() {
const mbForm = this.renderRoot.querySelector('mb-form') as MedblockForm;
if (mbForm.validate()) {
mbForm.insertContext();
Expand Down
2 changes: 1 addition & 1 deletion src/medblocks/form/plugins/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EhrElement from '../../EhrElement';
import type EhrElement from '../../EhrElement';

/*
* On submit, `getContext` for all empty context first runs, then the `export` runs.
Expand Down

0 comments on commit cce07f7

Please sign in to comment.