Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work and logs error in console #27

Open
anselmpaul opened this issue Feb 23, 2024 · 1 comment
Open

Does not work and logs error in console #27

anselmpaul opened this issue Feb 23, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@anselmpaul
Copy link

Describe the bug
The Form-CopyAction does not work. Nothing is copied to clipboard. On mount of the action, there is an JS error logged in the console:

Uncaught SyntaxError: missing ) after argument list
    at new AsyncFunction (<anonymous>)
    at safeAsyncFunction (livewire.js?id=6b5eb707:1249:21)
    at generateFunctionFromString (livewire.js?id=6b5eb707:1259:16)
    at generateEvaluatorFromString (livewire.js?id=6b5eb707:1264:16)
    at normalEvaluator (livewire.js?id=6b5eb707:1229:111)
    at evaluateLater (livewire.js?id=6b5eb707:1219:12)
    at livewire.js?id=6b5eb707:3776:35
    at Function.<anonymous> (livewire.js?id=6b5eb707:1850:58)
    at flushHandlers (livewire.js?id=6b5eb707:1353:48)
    at stopDeferring (livewire.js?id=6b5eb707:1358:7)
safeAsyncFunction @ livewire.js?id=6b5eb707:1249
generateFunctionFromString @ livewire.js?id=6b5eb707:1259
generateEvaluatorFromString @ livewire.js?id=6b5eb707:1264
normalEvaluator @ livewire.js?id=6b5eb707:1229
evaluateLater @ livewire.js?id=6b5eb707:1219
(anonymous) @ livewire.js?id=6b5eb707:3776
(anonymous) @ livewire.js?id=6b5eb707:1850
flushHandlers @ livewire.js?id=6b5eb707:1353
stopDeferring @ livewire.js?id=6b5eb707:1358
deferHandlingDirectives @ livewire.js?id=6b5eb707:1361
initTree @ livewire.js?id=6b5eb707:868
(anonymous) @ livewire.js?id=6b5eb707:816
(anonymous) @ livewire.js?id=6b5eb707:1037
onMutate @ livewire.js?id=6b5eb707:1037
setTimeout (async)
handleError @ livewire.js?id=6b5eb707:1201
safeAsyncFunction @ livewire.js?id=6b5eb707:1255
generateFunctionFromString @ livewire.js?id=6b5eb707:1259
generateEvaluatorFromString @ livewire.js?id=6b5eb707:1264
normalEvaluator @ livewire.js?id=6b5eb707:1229
evaluateLater @ livewire.js?id=6b5eb707:1219
(anonymous) @ livewire.js?id=6b5eb707:3776
(anonymous) @ livewire.js?id=6b5eb707:1850
flushHandlers @ livewire.js?id=6b5eb707:1353
stopDeferring @ livewire.js?id=6b5eb707:1358
deferHandlingDirectives @ livewire.js?id=6b5eb707:1361
initTree @ livewire.js?id=6b5eb707:868
(anonymous) @ livewire.js?id=6b5eb707:816
(anonymous) @ livewire.js?id=6b5eb707:1037
onMutate @ livewire.js?id=6b5eb707:1037
childList (async)
swapElements @ livewire.js?id=6b5eb707:7932
patch @ livewire.js?id=6b5eb707:7904
patchChildren @ livewire.js?id=6b5eb707:8077
patch @ livewire.js?id=6b5eb707:7921
patchChildren @ livewire.js?id=6b5eb707:8077
patch @ livewire.js?id=6b5eb707:7921
patchChildren @ livewire.js?id=6b5eb707:8077
patch @ livewire.js?id=6b5eb707:7921
patchChildren @ livewire.js?id=6b5eb707:8077
patch @ livewire.js?id=6b5eb707:7921
patchChildren @ livewire.js?id=6b5eb707:8077
patchChildren @ livewire.js?id=6b5eb707:8030
patch @ livewire.js?id=6b5eb707:7921
patchChildren @ livewire.js?id=6b5eb707:8077
patch @ livewire.js?id=6b5eb707:7921
patchChildren @ livewire.js?id=6b5eb707:8077
patch @ livewire.js?id=6b5eb707:7921
patchChildren @ livewire.js?id=6b5eb707:8077
patch @ livewire.js?id=6b5eb707:7921
patchChildren @ livewire.js?id=6b5eb707:8077
patch @ livewire.js?id=6b5eb707:7921
patchChildren @ livewire.js?id=6b5eb707:8077
patch @ livewire.js?id=6b5eb707:7921
morph @ livewire.js?id=6b5eb707:8122
morph2 @ livewire.js?id=6b5eb707:8898
(anonymous) @ livewire.js?id=6b5eb707:8958

To Reproduce

  1. Install the package in an existing admin panel
  2. Update the input as described
Forms\Components\TextInput::make('password')
                    ->label('Password')
                    ->required(fn (?User $record) => is_null($record))
                    ->minLength(8)
                    ->disabledOn(['edit'])
                    ->hintAction(Forms\Components\Actions\Action::make('password-reset')
                        ->hidden(fn (?User $record) => is_null($record))
                        ->label('reset')
                        ->link()
                        ->form(fn (?User $record) => [
                            Forms\Components\TextInput::make('link')
                                ->default(\Filament\Facades\Filament::getResetPasswordUrl(app('auth.password.broker')->createToken($record), $record))
                                ->suffixAction(CopyAction::make())
                        ])->modalHeading('Reset password')
                    )
                    ->password()
                    ->revealable(fn (?User $record) => is_null($record))
                    ->dehydrateStateUsing(fn (string $state): string => Hash::make($state))
                    ->dehydrated(fn (?string $state): bool => filled($state)),
  1. Click the copy button
  2. Nothing is copied to clipboard. An error is logged to the console on mount of the action modal.

Expected behavior
Input value is copied to clipboard. No error is logged

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Run on MacOS, current versions of Chrome & Safari, both local and hosted with SSL certificates.

@anselmpaul anselmpaul added the bug Something isn't working label Feb 23, 2024
@phpust
Copy link

phpust commented Feb 26, 2024

consider this as a dirty fix

class CopyAction extends BaseAction
{
    use HasCopyable {
        HasCopyable::getCopyable as getDefaultCopyable;
    }

    public function getCopyable(): ?string
    {
        if ($this->copyable === null) {
            return $this->evaluate(fn ($component) => '$wire.'.$this->changeFromDottedToBracket($component->getStatePath()));
        }

        return parent::getDefaultCopyable();
    }

    public function changeFromDottedToBracket($statePath): ?string{
        if (strpos($statePath, '.') === false) {
            return $statePath;
        } 

        $finalPath = "";
        foreach (explode(".", $statePath) as $key => $value) {
            if($value == "mountedTableActionsData"){
                $finalPath = $finalPath.$value;
            }else{
                $finalPath = $finalPath."['".$value."']";
            }
        }

        return $finalPath;
    }
}

looks like problem is with getStatePath , it must change from dotted to bracket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants