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

Use getFormFields to render select field will cause Vue.js error #175

Closed
yanhao-li opened this issue Jan 30, 2019 · 0 comments
Closed

Use getFormFields to render select field will cause Vue.js error #175

yanhao-li opened this issue Jan 30, 2019 · 0 comments
Assignees
Labels
type: documentation This issue means we need to improve docs type: enhancement New feature or request

Comments

@yanhao-li
Copy link

yanhao-li commented Jan 30, 2019

For example, if there is a select field named with "select_option_1" on the form, and when I'm trying to render the form using getFormFields as following

    public function getFormFields($user) {
        $fields = parent::getFormFields($user);
        $fields["select_option_1"] = "option_value";
        return $fields;
    }

This will trigger the javascript error:

edit:337 Uncaught ReferenceError: option_value is not defined

I noticed that "option_value" doesn't be treated as a string type when it was being pushed in Vuex.

    window.STORE.form.fields.push({
    name: 'select_option_1',
    value:  option_value       // WRONG, should be "option_value"
    })

I believe the problem is caused by the logic existed in _selector_input_store.blade.php file.

window.STORE.form.fields.push({
    name: '{{ $name }}',
    value: @if(isset($item) && is_numeric($item->$name)) {{ $item->$name }}
           @elseif(isset($item->$name)) {!! json_encode($item->$name) !!}
           @elseif(isset($formFieldsValue))
                @if (is_array($formFieldsValue))
                    @php
                        $formFieldsValue = array_first($formFieldsValue, null, '');
                    @endphp
                @endif
                @if (is_numeric($formFieldsValue)) {{ $formFieldsValue }}
                @else {!! $formFieldsValue !!}
                @endif
           @else
            ''
           @endif
})

The $formFieldsValue has been unescaped in the end, is this a bug or a feature?

A temporary possible workaround for this issue might be:

    public function getFormFields($user) {
        $fields = parent::getFormFields($user);
        $fields['select_option_1'] = "'" . $option_value . "'";
        return $fields;
    }
@ifox ifox added type: enhancement New feature or request type: documentation This issue means we need to improve docs labels Feb 12, 2019
@yanhao-li yanhao-li self-assigned this Jun 17, 2019
@ifox ifox closed this as completed May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation This issue means we need to improve docs type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants