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

How to configure Scalar #949

Closed
1 task done
TS1997 opened this issue Feb 18, 2025 · 3 comments
Closed
1 task done

How to configure Scalar #949

TS1997 opened this issue Feb 18, 2025 · 3 comments

Comments

@TS1997
Copy link

TS1997 commented Feb 18, 2025

Scribe version

4.39.0

Your question

How do I configure the parameters that exist here for the Scalar implementation? I looked at the view which iterates through external->html_attributes and tried entering the following properties one by one but I couldn't get any of them to work.

html_attributes => [
  'hideTestRequestButton' => true,
  'hideTestRequestButton' => "true",
  'hide-test-request-button' => true,
  'hide-test-request-button' => "true",
  'data-hide-test-request-button' => true,
  'data-hide-test-request-button' => "true",
]

What's the correct way of entering these configuration values?

Docs

@TS1997
Copy link
Author

TS1997 commented Feb 20, 2025

@shalvah I've done some additional testing of this now and can't get it to work. If I set the configuration like this I get an array to string conversion error in the blade template:

'external' => [
        'html_attributes' => [
            'data-configuration' => [
                'hideTestRequestButton' => true,
            ]
        ]
    ],

and if I try to work around that by encapsulating it in a json_encode like this I get an error in the browser console stating that there's a syntax error

'external' => [
        'html_attributes' => [
            'data-configuration' => json_encode([
                'hideTestRequestButton' => true,
            ])
        ]
    ],

Image

As I see it there's two ways to go about fixing this:

  1. Adding a check in the blade template that does a JSON.stringify on html_attribute values that are arrays
  2. Adding an additional external.configuration property to the config that's set like I did in the pull request earlier while keeping html_attributes as is

I can implement this and add a pull request for it but would like to check which way you prefer first? Or do you have another solution for it? Am I missing something here?

@shalvah
Copy link
Contributor

shalvah commented Feb 21, 2025

My guess is that it causes an error because the JSON includes double quotes, which terminate the attribute string. If we escape the quotes, we should be good. Try addslashes.

@TS1997
Copy link
Author

TS1997 commented Feb 21, 2025

I tried that and still got the same error but did manage to solve it by doing the following:

'external' => [
    'html_attributes' => [
        'data-configuration' => htmlspecialchars(json_encode([
            "hideTestRequestButton" => true,
        ]), ENT_QUOTES, 'UTF-8'),
    ]
],

@TS1997 TS1997 closed this as completed Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants