ZeroCharistmas
ZeroCharistmas
FFilament
Created by ZeroCharistmas on 7/10/2024 in #❓┊help
Repeater not saving pivot relationship
So the model function did end up being a pretty big part of it, which is a little weird because I thought I tested it out pretty thoroughly before. I'm just experiencing problems with the fullcalendar widget being unable to load the relationship for the create modal now.
9 replies
FFilament
Created by ZeroCharistmas on 7/10/2024 in #❓┊help
Repeater not saving pivot relationship
I should also mention that when an entry in the pivot table is created manually, it does not display in the repeater in the edit page.
9 replies
FFilament
Created by ZeroCharistmas on 7/10/2024 in #❓┊help
Repeater not saving pivot relationship
userEvents is a hasMany relationship on my model. The table also has a unique id.
9 replies
FFilament
Created by ZeroCharistmas on 7/10/2024 in #❓┊help
Repeater not saving pivot relationship
Commenting it out still doesn't help with the saving issue in the regular edit and create pages for the resource though, so I don't think that's the issue.
9 replies
FFilament
Created by ZeroCharistmas on 7/10/2024 in #❓┊help
Repeater not saving pivot relationship
The form schema is also used in a modal from the saade/filament-fullcalendar plugin and the repeater in the modal gives a
Call to a member function userEvents() on null
Call to a member function userEvents() on null
error without it.
9 replies
FFilament
Created by ZeroCharistmas on 6/12/2024 in #❓┊help
Text input with partially obfuscated data.
Here it is as a macro:
TextInput::macro("obfuscate", function(string $replacement = "*", array $ignore = [], int $revealFirst = 0, int $revealLast = 0){
$ignoreString = empty(array_filter($ignore)) ? '.' : '[^'.implode($ignore).']';
$revealFirst += 1;
$regexPattern = "/{$ignoreString}(?=.{{$revealLast}})(?<=.{{$revealFirst}})/";
$oldPlaceholder = $this->getPlaceholder();
return $this->formatStateUsing(fn () => null)
// Shows an obfuscated version of the value in a way that doesn't affect the data after save.
->placeholder(function($record) use ($oldPlaceholder, $replacement, $regexPattern): string {
if(is_null($record) || is_null($record[$this->getName()])){
return is_null($oldPlaceholder) ? $this->getLabel() : $oldPlaceholder;
} else {
return preg_replace($regexPattern, $replacement, $record[$this->getName()]);
}
})
// Prevents updating the field if it is null.
->before(function ($component, $state) {
if(empty($state)) {$component->dehydrated(false);}
})
// Allows clearing the data because the input is ignored when empty.
->suffixAction(
Action::make('clearData')
->label("Clear {$this->getLabel()}")
->icon('heroicon-m-x-mark')
->tooltip("Clear {$this->getLabel()}")
->requiresConfirmation()
->modalDescription("Are you sure you would like to clear this field?")
->action(function ($record, $set) {
$set($this->getName(), null);
if(!is_null($record))
{
$record->update([$this->getName() => null]);
}
})
->disabled(fn($record) => $record === null)
->hidden(fn($record) => $record === null)
);
});
TextInput::macro("obfuscate", function(string $replacement = "*", array $ignore = [], int $revealFirst = 0, int $revealLast = 0){
$ignoreString = empty(array_filter($ignore)) ? '.' : '[^'.implode($ignore).']';
$revealFirst += 1;
$regexPattern = "/{$ignoreString}(?=.{{$revealLast}})(?<=.{{$revealFirst}})/";
$oldPlaceholder = $this->getPlaceholder();
return $this->formatStateUsing(fn () => null)
// Shows an obfuscated version of the value in a way that doesn't affect the data after save.
->placeholder(function($record) use ($oldPlaceholder, $replacement, $regexPattern): string {
if(is_null($record) || is_null($record[$this->getName()])){
return is_null($oldPlaceholder) ? $this->getLabel() : $oldPlaceholder;
} else {
return preg_replace($regexPattern, $replacement, $record[$this->getName()]);
}
})
// Prevents updating the field if it is null.
->before(function ($component, $state) {
if(empty($state)) {$component->dehydrated(false);}
})
// Allows clearing the data because the input is ignored when empty.
->suffixAction(
Action::make('clearData')
->label("Clear {$this->getLabel()}")
->icon('heroicon-m-x-mark')
->tooltip("Clear {$this->getLabel()}")
->requiresConfirmation()
->modalDescription("Are you sure you would like to clear this field?")
->action(function ($record, $set) {
$set($this->getName(), null);
if(!is_null($record))
{
$record->update([$this->getName() => null]);
}
})
->disabled(fn($record) => $record === null)
->hidden(fn($record) => $record === null)
);
});
34 replies
FFilament
Created by ZeroCharistmas on 6/12/2024 in #❓┊help
Text input with partially obfuscated data.
Got a version of it working thanks to you guys and @Chris Reed! Because this is a field of a one-to-one relationship, the data didn't seem to be showing up in the edit page's mutateFormDataBeforeSave callback. Putting a before function on the input seems to be similar enough though, so I used that to disable dehydration on the component if it's null.
Forms\Components\TextInput::make('secret')
->label('secret')
// Clear the input field so the obfuscated value is shown in the placeholder.
->formatStateUsing(fn () => null)
// Shows an obfuscated version of the value in a way that doesn't affect the data during save.
->placeholder(fn ($record): string =>
preg_replace("/[^-](?=\\S{5})/", '*', $record->secret))
// Prevents updating the field if it is null.
->before(function ($component, $state) {
if(empty($state)) {$component->dehydrated(false);}
})
// Allows clearing the data because the input is ignored when empty.
->suffixAction(
Action::make('clearData')
->label('Clear Secret')
->icon('heroicon-m-x-mark')
->requiresConfirmation()
->modalDescription("Are you sure you would like to clear this field?")
->action(function ($record, $set) {
$set('secret', null);
$record->update(['secret' => null]);
})
)
Forms\Components\TextInput::make('secret')
->label('secret')
// Clear the input field so the obfuscated value is shown in the placeholder.
->formatStateUsing(fn () => null)
// Shows an obfuscated version of the value in a way that doesn't affect the data during save.
->placeholder(fn ($record): string =>
preg_replace("/[^-](?=\\S{5})/", '*', $record->secret))
// Prevents updating the field if it is null.
->before(function ($component, $state) {
if(empty($state)) {$component->dehydrated(false);}
})
// Allows clearing the data because the input is ignored when empty.
->suffixAction(
Action::make('clearData')
->label('Clear Secret')
->icon('heroicon-m-x-mark')
->requiresConfirmation()
->modalDescription("Are you sure you would like to clear this field?")
->action(function ($record, $set) {
$set('secret', null);
$record->update(['secret' => null]);
})
)
34 replies
FFilament
Created by ZeroCharistmas on 6/12/2024 in #❓┊help
Text input with partially obfuscated data.
No description
34 replies
FFilament
Created by ZeroCharistmas on 6/12/2024 in #❓┊help
Text input with partially obfuscated data.
I'ma try my hand at custom-field-smithy
34 replies
FFilament
Created by ZeroCharistmas on 6/12/2024 in #❓┊help
Text input with partially obfuscated data.
So your implementation is cool but it hits the same problem that mine is hitting. If the record is saved and the obfuscated input is left obfuscated, the secret field is overwritten with asterisks in the db(before encryption)
34 replies
FFilament
Created by ZeroCharistmas on 6/12/2024 in #❓┊help
Text input with partially obfuscated data.
Today's been kinda unexpectedly crazy for me. I'll check tomorrow. Thanks!
34 replies
FFilament
Created by ZeroCharistmas on 6/12/2024 in #❓┊help
Text input with partially obfuscated data.
The only time I ever want the value to be fully visible to a user is at the time it is entered fresh either in a create or edit action(when replacing the value). It should be obfuscated on the server side such that the original value doesn't show up in the html. After it is set, I want it to be partially obfuscatedbsuch that a user can infer that it is accurate. I don't want the method of obfuscation to change the saved value to its obfuscated version when other parts of the record are changed.
34 replies
FFilament
Created by ZeroCharistmas on 9/13/2023 in #❓┊help
Dynamically creating chart widgets, or creating a custom multi-chart widget?
That's what I was thinking. Couldn't get the chartjs library to load in the custom widget though for some reason
7 replies
FFilament
Created by ZeroCharistmas on 9/13/2023 in #❓┊help
Dynamically creating chart widgets, or creating a custom multi-chart widget?
Sure. The idea is to have a dashboard full of customizable charts backed by a model holding the chart configuration. Currently I just want to show a line chart widget for each chart configuration record featuring a count of newly created records over time.
7 replies