Is it possible to create an LWC input form that bypasses field-level security, while still leveraging the powerful UI brought by <lightning-input-field>
?
Im creating a generic filter component so admin can create filter criteria for any configured SObject and any of its fields. On submit, preventDefault()
is used to stop the usual record edit/creation that comes along with a <lightning-record-edit-form>
, since I don't need to save these filters in the backend. The user's input is extracted and used by the controller, and eventually dispatched in an event for parent components to handle.
The <lightning-input-field>
is useful because it automatically handles input UI, e.g. if given Contact.Birthdate, it will automatically render a datepicker element.
However, even though the form doesn't perform DML thanks to preventDefault()
, a user without CREATE permission still cannot use the form (they gets a toast error: Record is not createable
).
Is it possible to instruct the form to ignore field-level security, or some other way around it?
HTML:
<lightning-record-edit-form
object-api-name={objectType}
onsubmit={handleSubmit}>
<lightning-messages></lightning-messages>
<lightning-combobox
label="Operator"
value={operator}
options={operatorOptions}></lightning-combobox>
<lightning-input-field
field-name={fieldName}
value={value}></lightning-input-field>
<lightning-button type="submit" label="Submit"></lightning-button>
</lightning-record-edit-form>
JS:
import { LightningElement, api } from 'lwc';
export default class FilterController extends LightningElement {
@api objectType;
@api operator;
@api fieldName;
@api value;
handleSubmit(event) {
event.preventDefault();
let inputValue = event.detail.fields[this.fieldName];
let inputOperator = event.detail.fields["Operator"];
this.doSave(inputValue, inputOperator);
}
get operatorOptions() {
return ...;
}
doSave(value, operator) {
// Dispatches an event for parent component
}
}