F
Filamentโ€ข11mo ago
Wannes

Field is required CSV Importer

Hi, I keep getting the error "field is required", when using requiredMapping() on the CSV importer, although I specify a field.
public static function getColumns(): array
{
return [
ImportColumn::make('first_name')
->requiredMapping()
->label('Voornaam')
->guess(['voornaam', 'voornaam.'])
->example('John')
->rules(['required', 'max:255']),
ImportColumn::make('last_name')
->label('Achternaam')
->guess(['achternaam', 'naam', 'familienaam', 'achternaam.', 'naam.', 'familienaam.'])
->example('Doe')
->rules(['max:255']),
ImportColumn::make('email')
->label('Email')
->guess(['mail', 'e-mail', 'mail.', 'e-mail.', 'email.'])
->example('[email protected]')
->rules(['email', 'max:255']),
ImportColumn::make('phone')
->label('Telefoonnummer')
->guess(['gsm', 'telefoon', 'gsmnummer'])
->example('+32 470 52 60 33')
->rules(['max:255']),
ImportColumn::make('role')
->label('Rol')
->guess(['rol', 'role.', 'rol.'])
->example('Zaakvoerder')
->rules(['max:255']),
ImportColumn::make('notes')
->label('Notities')
->guess(['notities', 'opmerkingen', 'opmerking', 'opmerkingen.', 'opmerking.', 'note', 'notitie'])
->example('Bouwflow is fantastisch!'),
];
}
public static function getColumns(): array
{
return [
ImportColumn::make('first_name')
->requiredMapping()
->label('Voornaam')
->guess(['voornaam', 'voornaam.'])
->example('John')
->rules(['required', 'max:255']),
ImportColumn::make('last_name')
->label('Achternaam')
->guess(['achternaam', 'naam', 'familienaam', 'achternaam.', 'naam.', 'familienaam.'])
->example('Doe')
->rules(['max:255']),
ImportColumn::make('email')
->label('Email')
->guess(['mail', 'e-mail', 'mail.', 'e-mail.', 'email.'])
->example('[email protected]')
->rules(['email', 'max:255']),
ImportColumn::make('phone')
->label('Telefoonnummer')
->guess(['gsm', 'telefoon', 'gsmnummer'])
->example('+32 470 52 60 33')
->rules(['max:255']),
ImportColumn::make('role')
->label('Rol')
->guess(['rol', 'role.', 'rol.'])
->example('Zaakvoerder')
->rules(['max:255']),
ImportColumn::make('notes')
->label('Notities')
->guess(['notities', 'opmerkingen', 'opmerking', 'opmerkingen.', 'opmerking.', 'note', 'notitie'])
->example('Bouwflow is fantastisch!'),
];
}
Anyone has an idea how this comes?
No description
22 Replies
Wannes
WannesOPโ€ข11mo ago
Also the fields won't map automatically with the CSV, for some weird reason
dasK_
dasK_โ€ข10mo ago
Same issue here, did you have any luck fixing this? I'm seeing this in console livewire.js?id=a27c4ca2:347 Uncaught TypeError: Cannot read properties of null (reading 'name') double checked the csv, looks fine, I even did a dd in resolveRecord after taking the required selections out of the getColumns, that returned the correct array.. documentation says use Filament\Actions\Imports\ImportColumn; public function getColumns(): array { but when you generate the importer it does a public static function.. weird.
Hussain4real
Hussain4realโ€ข10mo ago
did you map them during the import?
dasK_
dasK_โ€ข10mo ago
yep, the selections are there
No description
dasK_
dasK_โ€ข10mo ago
but in the console
No description
Hussain4real
Hussain4realโ€ข10mo ago
You have to click on it and map it let's see your code
JJSanders
JJSandersโ€ข10mo ago
Yes update to latest version it has been fixed yesterday
nostrodamned
nostrodamnedโ€ข10mo ago
I still get the same issue - what did you update?
dasK_
dasK_โ€ข10mo ago
Sorry for late reply, class ProviderImporter extends Importer { protected static ?string $model = Provider::class; public static function getColumns(): array { return [ ImportColumn::make('name') ->label('Name') ->requiredMapping() ->rules(['required', 'max:255']), ImportColumn::make('logoUrl') ->rules(['max:255']), ImportColumn::make('network_type') ->rules(['max:255']), // ImportColumn::make('country') // ->relationship(resolveUsing: function ($state) { // return Country::where('name', $state)->first()?->id; // }) ]; } public function resolveRecord(): ?Provider { return Provider::firstOrNew([ 'name' => $this->data['Name'], ]); return new Provider(); } Note: I commented out the relationship column just to show that I'm not doing anything complicated updated to v3.2.33 and still having the same issue unfortunately
JJSanders
JJSandersโ€ข10mo ago
din you run npm npm run dev?
dasK_
dasK_โ€ข10mo ago
Yep, npm run build then npm run dev csv should just be UTF-8 encoding right?
JJSanders
JJSandersโ€ข10mo ago
Yes
dasK_
dasK_โ€ข10mo ago
dd($this->data); in resolveRecord after removing the requiredMapping and rules for required array:7 [โ–ผ // app\Filament\Imports\ProviderImporter.php:35 "ID" => "174" "Name" => "Vodafone Albania" "Logo url" => "" "Network type" => "4g" "Country" => "Albania" "Created at" => "2024-02-08 03:48:26" "Updated at" => "2024-02-08 03:59:41" ]
JJSanders
JJSandersโ€ข10mo ago
What is your error?
dasK_
dasK_โ€ข10mo ago
No description
dasK_
dasK_โ€ข10mo ago
console says livewire.js?id=a27c4ca2:347 Uncaught TypeError: Cannot read properties of null (reading 'name') I did upgrade from filament 2 when 3 came out, if that makes a difference
JJSanders
JJSandersโ€ข10mo ago
GitHub
Release v3.2.34 ยท filamentphp/filament
What's Changed adding header to sidebar dropdown by @atmonshi in #11384 Add mask to TextInputColumn by @rappasoft in #11386 v3.2.33: Fix installing Filament without filament/filament due to m...
nostrodamned
nostrodamnedโ€ข10mo ago
Same issue On 3.2.34
dasK_
dasK_โ€ข10mo ago
same issue ๐Ÿ˜ฆ
nostrodamned
nostrodamnedโ€ข9mo ago
Any updates on this we still have same issue? bump ๐Ÿ™‚ our issue was joshembling/image-optimizer causing the issue! for all who may come across it.!!
dasK_
dasK_โ€ข9mo ago
I have this package as well, thank you!
nostrodamned
nostrodamnedโ€ข9mo ago
๐Ÿ˜†
Want results from more Discord servers?
Add your server