F
FilamentJean Roumeau

Validate import before inserting records.

Hello. I'm playing around with import actions to see if it suits my needs. Do yo know if its possible to validate the CSV before inserting data in the database?. I need to be able to cancel de import if data is invalid. I read on docs that the import process collects all failed rows but does that mean that valid data get imported? This is a problem to me as partial import is hard to handle and will prefer to avoid import at all if data fails validation. In order to fix it and attempt the import again. Thanks.
Jean Roumeau
Jean Roumeau14d ago
According to docs (https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import#customizing-import-validation-messages) it also says that "the import system will automatically validate the CSV file before it is imported". But ot doesn't seem to work like this.
Tetracyclic
Tetracyclic14d ago
https://github.com/filamentphp/filament/blob/2f5ac6078d522672a437b56d573a78ecf869a67a/packages/actions/src/Imports/Importer.php#L142 The Importer uses the validation rules from the column to validate it, but it processes each row separately, and it chunks the CSV across multiple jobs. You can pass in a custom import job that extends ImportCsv. You could alter it to first run through the records and validate them and only then if there are no failures, run it through the standard importer. But you'd need to ensure that all of the records are processed in a single chunk and not sent to multiple jobs. https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import#customizing-the-import-job https://github.com/filamentphp/filament/blob/2f5ac6078d522672a437b56d573a78ecf869a67a/packages/actions/src/Imports/Jobs/ImportCsv.php#L76
Want results from more Discord servers?
Add your server
More Posts
Dont Reset FieldHow do I prevent any field from resetting after the form is submitted?How do I programatically log into filament?My Filament has resource pages for admins and non-admins. - I have a user resource and a table-actioImporting a module script failed.Hello everyone, I have the following problem, it breaks the JS script completely because of this, thRelationship Manager: Open in same window (non-modal)Say I have a `UserResource` and a `PostResource`. When I add a `PostRelationManager`, it opens postOpen url in modal actionHello, I am trying to open an url with parameters in a table modal. I want to open a modal, ask theHow to change color palette dynamicallyMy application is multitenant and I would like to change the color palettes according to the client,Custom ValidationMessages for minDate/maxDateI have tried the following, but the html5 validation still shows the default browser error. Do i neeModal actionHow can I do this in a modal window, since there is no ->columns() optionRepeater and auto-increment fieldI have a form with a repeater and I have a field for the number of the element. I want that field tBuild not picking up my Theme CSSI've added this plugin https://filamentphp.com/plugins/mokhosh-kanban and I'm updating the card viewMarkdownEditor not recognising inputI have a Form with a Markdown Editor, it is a required field. When I enter some text and try to savCustom Save Button for Create/Edit with Disable on FileUploadHello Filament Friends, I have a problem with implementing different Save Buttons. My process shoul