Skip to content

Commit

Permalink
lmb-181: make it possible to let the label show the isRequird pill
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasVanHoof committed Jan 14, 2025
1 parent 2b4887e commit 0b99724
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
1 change: 1 addition & 0 deletions app/components/rdf-input-fields/custom-address-input.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<RdfInputFields::CustomFieldWrapper
@field={{@field}}
@form={{@form}}
@graphs={{@graphs}}
@formStore={{@formStore}}
>
<div class="au-o-box au-u-background-gray-100 au-u-margin-top-tiny">
Expand Down
1 change: 1 addition & 0 deletions app/components/rdf-input-fields/custom-date-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@inline={{true}}
@field={{@field}}
@form={{@form}}
@graphs={{@graphs}}
@formStore={{@formStore}}
>
<RdfInputFields::RdfDateInput
Expand Down
15 changes: 1 addition & 14 deletions app/components/rdf-input-fields/custom-field-wrapper.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
<div class="au-u-flex au-u-flex--between">
<div class="flex-grow">
<div class="au-u-flex au-u-flex--row">
<AuLabel
for={{this.inputId}}
@error={{this.hasErrors}}
@warning={{this.hasWarnings}}
@required={{this.isRequired}}
>{{this.title}}</AuLabel>
<AuLabel @required={{this.isRequired}}>{{this.title}}</AuLabel>
<AuButton
@skin="link-secondary"
@icon="pencil"
Expand Down Expand Up @@ -44,14 +39,6 @@
</AuButton>
</div>
</div>

{{#each this.errors as |error|}}
<AuHelpText @error={{true}}>{{error.resultMessage}}</AuHelpText>
{{/each}}

{{#each this.warnings as |warning|}}
<AuHelpText @warning={{true}}>{{warning.resultMessage}}</AuHelpText>
{{/each}}
{{/unless}}

<RdfInputFields::CrudCustomFieldModal
Expand Down
30 changes: 30 additions & 0 deletions app/components/rdf-input-fields/custom-field-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { tracked } from '@glimmer/tracking';

import { consume } from 'ember-provide-consume-context';
import { task } from 'ember-concurrency';
import { validationsForFieldWithType } from '@lblod/submission-form-helpers';

import { JSON_API_TYPE } from 'frontend-lmb/utils/constants';

Expand Down Expand Up @@ -37,4 +38,33 @@ export default class RdfInputFieldsCustomFieldWrapperComponent extends Component
this.onFormUpdate();
}
});

// From ember-submission-form-fields component: input-field.js
// We cannot access these properties as they are in the component itself and this is just a wrapper
get isRequired() {
return (
!this.args.show &&
this.constraints.some(
(constraint) =>
constraint.type.value ===
'http://lblod.data.gift/vocabularies/forms/RequiredConstraint'
)
);
}

get constraints() {
return validationsForFieldWithType(this.args.field.uri, this.storeOptions);
}

get storeOptions() {
return {
formGraph: this.args.graphs.formGraph,
sourceGraph: this.args.graphs.sourceGraph,
metaGraph: this.args.graphs.metaGraph,
sourceNode: this.args.sourceNode,
store: this.args.formStore,
path: this.args.field.rdflibPath,
scope: this.args.field.rdflibScope,
};
}
}
1 change: 1 addition & 0 deletions app/components/rdf-input-fields/custom-number-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@inline={{true}}
@field={{@field}}
@form={{@form}}
@graphs={{@graphs}}
@formStore={{@formStore}}
>
<RdfInputFields::NumericalInput
Expand Down
1 change: 1 addition & 0 deletions app/components/rdf-input-fields/custom-string-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@inline={{true}}
@field={{@field}}
@form={{@form}}
@graphs={{@graphs}}
@formStore={{@formStore}}
>
<RdfInputFields::Input
Expand Down
1 change: 1 addition & 0 deletions app/components/rdf-input-fields/custom-text-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@inline={{true}}
@field={{@field}}
@form={{@form}}
@graphs={{@graphs}}
@formStore={{@formStore}}
>
<RdfInputFields::TextArea
Expand Down

0 comments on commit 0b99724

Please sign in to comment.