You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I've been trying to wrap my head around adding an info Icon in the label of each input with a label and a "floatingHelp" attribute (for a tooltip).
I've started of with the example of how to add an astrerix to the label if required and how to get the icon in with the other example.
So far it works well enough, but now as I also want to manipulate the options of radio / checkbox inputs, it only works either for the label / legend input or it breaks the functionality of the input field. All the option inputs have their own name / value and the radio buttons are all selected. I also recieve a W350 warning if that helps, but I couldn't figure out what that means.
Here's my formkit.config.js
import{de,en}from"@formkit/i18n";import{createAutoAnimatePlugin}from"@formkit/addons";import{pluginasinertiaPlugin}from"formkit-addon-inertia";importPhInfofrom"~icons/ph/info?raw";// ...constformKitConfig={locales: { de, en },locale: "de",// defaulticons: {},plugins: [createAutoAnimatePlugin(),inertiaPlugin,labelEnhancementPlugin],};exportdefaultformKitConfig;/** * Start Part of the label enhancement plugin */constisCheckboxAndRadioMultiple=(node)=>(node.props.type==="checkbox"||node.props.type==="radio")&&node.props.options;constupdateLabel=(node)=>{constisMultiOption=isCheckboxAndRadioMultiple(node);constfloatingHelpText=node.props.attrs["floatingHelp"];constisRequired=node.props.parsedRules.some((rule)=>rule.name==="required");// if we're going to modify the schema then we need// to update the schemaMemoKey so we don't get an// invalid cached schema.node.props.definition.schemaMemoKey=`required_${isMultiOption ? "multi_" : ""}${floatingHelpText ? "info_" : ""}${node.props.definition.schemaMemoKey}`;// no idea why we need to set this like this, but it works.node.context.isReq=isRequired ? "*" : " ";node.context.infoIcon=floatingHelpText
? `<div class="info-btn" data-tippy-content="${floatingHelpText}">${PhInfo}</div>`
: "";constschemaFn=node.props.definition.schema;node.props.definition.schema=(sectionsSchema={})=>{constlabelSchema={attrs: {innerHTML: '$label + "" + $isReq + "" + $infoIcon',},children: null,};constoptionsSchema={for: ["item","index","$options"],children: [{$cmp: "FormKit",props: {name: "$item.name",type: node.props.type,label: "$item.label",floatingHelp: "$item.attrs.floatingHelp",},},],};constlocaleSchema={
...sectionsSchema,[isMultiOption ? "legend" : "label"]: labelSchema,children: null,options: isMultiOption ? optionsSchema : null,};returnschemaFn(localeSchema);};};// modifies label (info icon and asteriks)functionlabelEnhancementPlugin(node){node.on("created",()=>{updateLabel(node);});node.on("prop",({ payload })=>{if(payload.prop==="attrs"||payload.prop==="locale")updateLabel(node);});}
I run the function twice, because my data (JSON data) comes from the backend and so I don't have it on create always.
Can someone help me?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
So I've been trying to wrap my head around adding an info Icon in the label of each input with a label and a "floatingHelp" attribute (for a tooltip).
I've started of with the example of how to add an astrerix to the label if required and how to get the icon in with the other example.
So far it works well enough, but now as I also want to manipulate the options of radio / checkbox inputs, it only works either for the label / legend input or it breaks the functionality of the input field. All the option inputs have their own name / value and the radio buttons are all selected. I also recieve a W350 warning if that helps, but I couldn't figure out what that means.
Here's my formkit.config.js
I run the function twice, because my data (JSON data) comes from the backend and so I don't have it on create always.
Can someone help me?
Thanks and cheers!
Beta Was this translation helpful? Give feedback.
All reactions