Skip to content

Commit

Permalink
fix(bhFindPatient): implement validation trigger
Browse files Browse the repository at this point in the history
This commit implements a validation trigger on the bhFindPatient
component using the `validation-trigger` flag.  It is expected to be a
boolean value indicating whether the validation should be triggered
or not.
  • Loading branch information
Jonathan Niles authored and jniles committed Oct 9, 2016
1 parent 958798b commit 0852758
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
15 changes: 10 additions & 5 deletions client/src/js/components/bhFindPatient.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ angular.module('bhima.components')
controller: FindPatientComponent,
templateUrl : 'partials/templates/bhFindPatient.tmpl.html',
bindings: {
onSearchComplete: '&', // bind callback to call when data is available
onRegisterApi: '&', // expose force refresh API
required: '<', // bind the required (for ng-required)
suppressReset: '@', // bind a string
onSearchComplete: '&', // bind callback to call when data is available
onRegisterApi: '&', // expose force refresh API
required: '<', // bind the required (for ng-required)
validationTrigger: '<', // bind validation trigger
suppressReset: '@' // bind a string
}
});

Expand All @@ -27,8 +28,12 @@ FindPatientComponent.$inject = [
*
* SUPPORTED ATTRIBUTES:
* - on-search-complete : a callback function called with the found patient
* - suppress-reset: a boolean value to
* - suppress-reset: a boolean value to suppress reset calls from the external
* api
* - on-registry-api: a callback to be called with the component's api
* - required: binds ng-required on the input.
* - validationTrigger: binds a boolean to indicate if the components validation
* should be run
*/
function FindPatientComponent(Patients, AppCache, Notify) {
var vm = this;
Expand Down
3 changes: 2 additions & 1 deletion client/src/partials/cash/cash.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
<bh-find-patient
on-search-complete="CashCtrl.usePatient(patient)"
on-register-api="CashCtrl.onRegisterApiCallback(api)"
required="required">
validation-trigger="CashVoucherForm.$submitted"
required="true">
</bh-find-patient>

<bh-date-editor
Expand Down
4 changes: 3 additions & 1 deletion client/src/partials/patient_invoice/patientInvoice.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
<bh-find-patient
suppress-reset="true"
on-search-complete="PatientInvoiceCtrl.setPatient(patient)"
on-register-api="PatientInvoiceCtrl.onPatientSearchApiCallback(api)">
on-register-api="PatientInvoiceCtrl.onPatientSearchApiCallback(api)"
validation-trigger="detailsForm.$submitted"
>
</bh-find-patient>
</div>

Expand Down
4 changes: 2 additions & 2 deletions client/src/partials/templates/bhFindPatient.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="form-group has-feedback"
ng-class="{
'has-success': !$ctrl.showSearchView && $ctrl.loadStatus=='loaded',
'has-error': !$ctrl.showSearchView && $ctrl.loadStatus=='error'
'has-error': (!$ctrl.showSearchView && $ctrl.loadStatus=='error') || ($ctrl.validationTrigger && $ctrl.loadStatus != 'loaded')
}"
>
<label class="control-label text-capitalize">{{ "FORM.LABELS.PATIENT" | translate }}</label>
Expand Down Expand Up @@ -57,7 +57,7 @@
<span class="input-group-btn" ng-if="$ctrl.selected == $ctrl.options.findById">
<button
type="button"
class="btn btn-success"
class="btn btn-default"
ng-disabled="FindPatientForm.idInput.$invalid"
ng-click="$ctrl.submit()"
data-find-patient-submit>
Expand Down

0 comments on commit 0852758

Please sign in to comment.