Comments (6)
@bushbill Happy to try to help out. For Nuxt all you need to do is install @formkit/nuxt
from npm and in your Nuxt config file add @formkit/nuxt
to your modules list.
// nuxt.config
...
modules: [
'@formkit/nuxt',
],
...
Then, adjacent to your Nuxt config file in your project root create a formkit.config
file. It can end in .ts
, .mjs
or .js
depending on your project's needs.
Using the example config file from the documentation (which is only a partial implementation of a Tailwind theme for demonstration purposes) means that your formkit.config
file would would look like this:
export default {
config: {
rootClasses (sectionKey, node) {
const type = node.props.type
const classConfig = {
outer: 'mb-5',
legend: 'block mb-1 font-bold',
label () {
if (type === 'text') { return 'block mb-1 font-bold' }
if (type === 'radio') { return 'text-sm text-gray-600 mt-0.5' }
},
options () {
if (type === 'radio') { return 'flex flex-col flex-grow mt-2' }
},
input () {
if (type === 'text') { return 'w-full h-10 px-3 mb-2 text-base text-gray-700 placeholder-gray-400 border rounded-lg focus:shadow-outline' }
if (type === 'radio') { return 'mr-2' }
},
wrapper () {
if (type === 'radio') { return 'flex flex-row flex-grow' }
},
help: 'text-xs text-gray-500',
}
function createClassObject (classesArray) {
const classList = {}
if (typeof classesArray !== 'string') return classList
classesArray.split(' ').forEach(className => {
classList[className] = true
})
return classList
}
const target = classConfig[sectionKey]
if (typeof target === 'string') {
return createClassObject(target)
} else if (typeof target === 'function') {
return createClassObject(classConfig[sectionKey]())
}
}
}
}
That should automatically apply some Tailwind classes to every FormKit input in your project, based on the logic represented in the config.
from formkit.
@andrew-boyd Thank you.
But if I include this config above into formit.config.js I got the following error after running "yarn dev -o":
ERROR [worker] Cannot read properties of undefined (reading 'split') 08:14:52
at createClassObject (.nuxt/dist/server/server.mjs:11768:22)
at Proxy.rootClasses (.nuxt/dist/server/server.mjs:11777:16)
at .nuxt/dist/server/server.mjs:3816:43
at watch (.nuxt/dist/server/server.mjs:9131:17)
at Proxy.<anonymous> (.nuxt/dist/server/server.mjs:9046:39)
at Object.get (.nuxt/dist/server/server.mjs:3814:34)
at Reflect.get (<anonymous>)
at Object.get (node_modules/@vue/reactivity/dist/reactivity.cjs.js:428:29)
at .nuxt/dist/server/server.mjs:2716:33
at Array.reduce (<anonymous>)
ERROR [proxy] connect ENOENT /tmp/nitro/worker-28538-1.sock 08:14:53
at PipeConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)
What could be wrong?
from formkit.
@bushbill the code example looks like its missing an undefined check:
Change this:
function createClassObject (classesArray) {
const classList = {}
classesArray.split(' ').forEach(className => {
classList[className] = true
})
return classList
}
To this:
function createClassObject (classesArray) {
const classList = {}
if (typeof classesArray !== 'string') return classList
classesArray.split(' ').forEach(className => {
classList[className] = true
})
return classList
}
from formkit.
Thanks @justin-schroeder — I'll get this updated in the docs examples. Thought we'd already done that but they must not have made it out the door.
from formkit.
Ah... they were there just cached. I had to do a hard reload on the page in my browser. Sorry for steering you wrong with out of date example code @bushbill!
I've updated my earlier response to include the correct revision.
from formkit.
Closing since this seems to be resolved — feel free to reopen if there is a bug here
from formkit.
Related Issues (20)
- TS issue on FormKitMessages component
- [BUG] SSR + v-model + local Storage HOT 3
- Select element remains in placeholder state when option selected using option groups with placeholder set
- valid state only correctly changes when other inputs are present HOT 1
- Repeater sortability not functioning properly HOT 1
- It is impossible to add a new tag if there is already a tag in the options with the same root or a part that matches the text of the new tag in taglist field HOT 2
- Clicking on this area will not trigger the Select menu
- formkit/i18n: Validation rule's message is incorrect when using array syntax for the validation
- `autocomplete`: Async options not filterable HOT 5
- Mask input and autocomplete failing validation HOT 1
- Errors don't show with more groups HOT 3
- Repeater should consistently render when the default slot is empty HOT 1
- Mixed order of identical items in dynamic list
- <FormKit type="mask"> renders <input type="mask"> HOT 3
- datetime-local field with initial value resets itself in firefox after the entry of a 0
- FormKit datepicker component: enter key submits the form and display the calendar popup
- `childRemoved` event not triggered for type list HOT 1
- setting Buddist locale breaks datepicker HOT 2
- Changing `datepicker` value makes it to autofocus on Safari
- Pro Inputs - Potential Memory Leak Issue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formkit.