Custom form fields

I'm trying to make a custom form field to override the custom WYSIWYG form field. I've followed this guide https://twillcms.com/guides/creating_custom_components_form_fields_and_blocks.html I feel like there are some steps left out of there. For example where do i need to define the Vue component? Is there a config file for that. I've been snooping around in twill source and i see everything is stored in A17Config but how could i override this or solve this. Maybe there is another way to add custom css to a WYSIWYG form field or alter tiptap config?
Twill
68 Replies
thelongestsigh
thelongestsighOP•2y ago
I'm also wondering do you use Quill or Tiptap?
ifox
ifox•2y ago
Hi @thelongestsigh sorry support has been a bit slow on discord in the past few days. In twill 3 Tiptap is the new default type we use for WYSIWYG fields. That guide specifies the location of Vue components:
File:

resources/assets/js/components/HelloWorld.vue
File:

resources/assets/js/components/HelloWorld.vue
thelongestsigh
thelongestsighOP•2y ago
In the example you use this, but how do you define the component name "a17-custom-number" <a17-custom-number label="{{ $label }}" :precision="{{ $precision }}" currency="{{ $currency }}" decimal-separator="{{ $decimalSeparator }}" thousand-separator="{{ $thousandSeparator }}" @include('twill::partials.form.utils._field_name') in-store="value" ></a17-custom-number>
ifox
ifox•2y ago
GitHub
twill/twill.php at 29db4a8c6ce25263c0c3f86ecdff568b0d815a12 · area1...
Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive, powerful and flexible. Chat with us on Discord at https://discord.gg/c...
ifox
ifox•2y ago
It's automatically registered in the vue app for you from its path So having resources/assets/js/components/CustomNumber.vue would compile as a17-custom-number
thelongestsigh
thelongestsighOP•2y ago
ohh right thanks for the tip i was already wondering how it was possible @ifox.dev I tried implementing this the way it's described in the documentation. But i keep getting the same error message.
thelongestsigh
thelongestsighOP•2y ago
No description
thelongestsigh
thelongestsighOP•2y ago
No description
thelongestsigh
thelongestsighOP•2y ago
This is my form
No description
thelongestsigh
thelongestsighOP•2y ago
this is my partials form
No description
thelongestsigh
thelongestsighOP•2y ago
thelongestsigh
thelongestsighOP•2y ago
No description
ifox
ifox•2y ago
put it under views/twill not viewa/admin in Twill 3
thelongestsigh
thelongestsighOP•2y ago
Tried it but still doesn't work
ifox
ifox•2y ago
with the same error?
thelongestsigh
thelongestsighOP•2y ago
Yes. Do i need to run 'php artisan twill:build'?
ifox
ifox•2y ago
yes, but that won't fix this error. before creating a form field partial try to use the Vue component directly into your form
thelongestsigh
thelongestsighOP•2y ago
the page gets loaded but i think the vue component is ignored since there is no change
thelongestsigh
thelongestsighOP•2y ago
I tried both ways but no luck
No description
ifox
ifox•2y ago
ran twill:build successfully? Do you find your code in the compiled form js file?
thelongestsigh
thelongestsighOP•2y ago
No description
thelongestsigh
thelongestsighOP•2y ago
Seems like an issue with tiptap Any ideas on this?
ifox
ifox•2y ago
I'm going to need to see your Vue component file
ifox
ifox•2y ago
tiptap is already in twill, and I'm not sure how you're implementing it in your component
thelongestsigh
thelongestsighOP•2y ago
i know .. but i'm trying to add an extra button to the tiptap editor the implementation is the same as on the link i sent you
thelongestsigh
thelongestsighOP•2y ago
No description
ifox
ifox•2y ago
Twill is on Vue 2 so you can't use the vue 3 version of tiptap
thelongestsigh
thelongestsighOP•2y ago
thanks for the info i managed to build where are the dist files located?
ifox
ifox•2y ago
at the end of twill:build it is copying them to your public folder under assets
thelongestsigh
thelongestsighOP•2y ago
No i still couldn't find it. I can't load the component in any way Maybe there is another way to add custom css to a WYSIWYG form field or alter tiptap config?
ifox
ifox•2y ago
css you can add through the extra_css blade stack, but altering tiptap config beyond the toolbar options that twill makes available also requires rebuilding the assets the fact that you ran into an issue with tiptap for vue3 means the build found your component can't find text-edit in any of the dist files?
thelongestsigh
thelongestsighOP•2y ago
nope nowhere in there main-form, main-buckets and all others don't have it
thelongestsigh
thelongestsighOP•2y ago
I've tried overriding the vendor WysiwgTiptap.vue which also didn't work.
No description
ifox
ifox•2y ago
alright, I'll try to reproduce. What is your node version?
thelongestsigh
thelongestsighOP•2y ago
v16.18.1
ifox
ifox•2y ago
Ok, on Twill 3 I'd recommend 18 but probably not related
thelongestsigh
thelongestsighOP•2y ago
oh right did you reproduce?
ifox
ifox•2y ago
I can't focus on this right now sorry, but I will and get back to you, please be patient
thelongestsigh
thelongestsighOP•2y ago
Any idea when, i have a project to deliver and this is the last step to finish it
ifox
ifox•2y ago
just tested the hello world example successfully: in resources/assets/js/components/HelloWorld.vue:
<template>
<!-- eslint-disable -->
<div>
Hello {{ name }}
</div>
</template>

<script>
/* eslint-disable */

export default {
props: ['name']
}
</script>
<template>
<!-- eslint-disable -->
<div>
Hello {{ name }}
</div>
</template>

<script>
/* eslint-disable */

export default {
props: ['name']
}
</script>
in resources/views/twill/partials/form/_hello-world.blade.php:
<a17-hello-world name="test"></a17-hello-world>
<a17-hello-world name="test"></a17-hello-world>
and in my form: @formField('hello-world') renders "Hello test" on my form all I did was php artisan twill:build after creating the vue file
thelongestsigh
thelongestsighOP•2y ago
I'll try Still no luck. Thinking there is a problem with my project so i'll try in another one
thelongestsigh
thelongestsighOP•2y ago
Tried it in another project and i still get this. Would you mind sharing the project you tested in? So i can test it locally
No description
ifox
ifox•2y ago
your form blade file should be under resources/views/twill/pages it's currently still under admin. Did you upgrade from twill 2? oh I guess you tried in a twill 2 project
thelongestsigh
thelongestsighOP•2y ago
yep i tried in a twill 2 project
ifox
ifox•2y ago
where did you put the partial?
thelongestsigh
thelongestsighOP•2y ago
i'm trying in a new fresh project right now to see the results
thelongestsigh
thelongestsighOP•2y ago
No description
ifox
ifox•2y ago
twill 2 doesn't know about a twill folder it should be under admin
thelongestsigh
thelongestsighOP•2y ago
No description
thelongestsigh
thelongestsighOP•2y ago
I still haven't been able to resolve it but i've made a repository with the new project i've created and copied your HelloWorld.vue component in. Maybe if you can have a look at it
thelongestsigh
thelongestsighOP•2y ago
GitHub
GitHub - toonvank/Twill-form-test: Twill form test
Twill form test. Contribute to toonvank/Twill-form-test development by creating an account on GitHub.
thelongestsigh
thelongestsighOP•2y ago
I've created an issue on github https://github.com/area17/twill/issues/2260
GitHub
Not able to load a custom component · Issue #2260 · area17/twill
Description I am trying to make a custom component for adding custom buttons to a wysiwyg field in twill admin forms. I've created a project from scratch trying to implement the steps. This git...
thelongestsigh
thelongestsighOP•2y ago
@ifox.dev could you please look into this?
ifox
ifox•2y ago
Hi @thelongestsigh I will this week.
thelongestsigh
thelongestsighOP•2y ago
Thank you, appreciate it Any updates on this?
ifox
ifox•2y ago
Hi @thelongestsigh sorry for the delay, this is my next priority now that 3.0.2 is released
_crp87
_crp87•2y ago
Hey 👋 how would you provide a custom form field like this wysiwyg editor from within a package? Can they also be registered from package path inside package Service Provider?
ifox
ifox•2y ago
@thelongestsigh I tested your repository and it worked without changing anything
No description
ifox
ifox•2y ago
I did find a syntax error in your blade file that could explain it not working for you if you're using a browser that doesn't like it, but I have no problem with it in chrome:
No description
seeni333
seeni333•2y ago
How to create custom form filed becuase in Twill 3 all fields are render dynamically and also all view files are inside in vendor folder? how to create custom field in controller in getForm method?
thelongestsigh
thelongestsighOP•2y ago
I tried both on chrome and firefox but i'm really baffled this is what i see
thelongestsigh
thelongestsighOP•2y ago
No description
ifox
ifox•2y ago
@thelongestsigh did you try with a simple string first, it doesn't seem like your form blade file is even loading on your end @seeni333 views can be published, like with any other Laravel package. and form fields OOP classes can be extended.
seeni333
seeni333•2y ago
ok thank you @ifox.dev
thelongestsigh
thelongestsighOP•2y ago
Yea i tried it
ifox
ifox•2y ago
I'm not sure how to help, at this point I would need you to screenshare to see the problem myself since I can't reproduce it even with your repository.
Want results from more Discord servers?
Add your server