5

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
    }
}
0

2 Answers 2

4

No, it's not possible. Instead, you'd have to use getObjectInfo and render your own UI.

0

If your user has edit permission on the object, you can simply pass record-id={recordId} to the <lightning-record-edit-form> tag and it works. LDS will consider it is for update and render <lightning-record-edit-form> properly. After this, you can keep using preventDefault() in js file and do whatever you need with the values user entered.

The only challenge here is getting recordId, If you are using your component on any object's lightning record page by adding @recordId to js file you can get record id. If your component is generic hard code some random record id from the objectType you are passing to <lightning-record-edit-form>.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .