Giter VIP home page Giter VIP logo

Comments (7)

fenilli avatar fenilli commented on June 24, 2024 1

As a workaround ( not sure what the full implications it is yet ) you can remove the line:

node.props.definition.schemaMemoKey = `required_${node.props.definition.schemaMemoKey}`  

from formkit.

justin-schroeder avatar justin-schroeder commented on June 24, 2024 1

Thanks for the heads up!

In version 1.4 we introduced the context.state.required which indicates whether or not an input is actually required or not. This makes all this much easier.

https://formkit.link/39ef1ce063059b72671fc5f15d1295c6

Docs have been updated with this version too 👍

from formkit.

gbyesiltas avatar gbyesiltas commented on June 24, 2024

I have a different version of this plugin (probably from before so may be missing some fixes/features that were added later) but it does work with dropdowns and autocompletes:

import {
  type FormKitExtendableSchemaRoot,
  type FormKitNode,
} from "@formkit/core";

// https://formkit.com/essentials/examples
const isCheckboxAndRadioMultiple = (node: FormKitNode) =>
  (node.props.type === "checkbox" || node.props.type === "radio") &&
  node.props.options;



export default function addAsteriskPlugin(node: FormKitNode) {
  node.on("created", () => {
    if (!node.props.definition || !node.context || node.type !== "input") {
      return;
    }

    const inputTypeUniqueKey = node.props.definition.schemaMemoKey || node.context.type;
    node.props.definition.schemaMemoKey = `required_${isCheckboxAndRadioMultiple(node) ? 'multi_' : ""}${inputTypeUniqueKey}`
    node.context.isRequired = node.props.parsedRules.some(
      (rule: { name: string }) => rule.name === "required",
    );

    node.on('prop:validation', () => {
      if (!node.context) return;
      node.context.isRequired = node.props.parsedRules.some((rule: { name: string }) => rule.name === 'required')
    })

    // it would be better to have a proper type check here, but this plugin comes straight
    // from the FormKit site, so we'll just assert this and assume they know what they're doing
    const schemaFn = node.props.definition
      .schema as FormKitExtendableSchemaRoot;

    node.props.definition.schema = (sectionsSchema = {}) => {
      sectionsSchema[isCheckboxAndRadioMultiple(node) ? 'legend' : 'label'] = {
        children: ['$label', {
          $el: 'span',
          if: '$isRequired',
          attrs: {
            class: '$classes.asterisk',
          },
          children: ['*']
        }]
      }

      return schemaFn(sectionsSchema)
    }
  })
}

from formkit.

fenilli avatar fenilli commented on June 24, 2024

Ok so looking into it, seens like a problem with autocomplete and repeater autocomplete and dropdown: https://formkit.link/53b72e2a6eb3725163af184064d20923

And it has something to do with the schemaMemoKey node.props.definition.schemaMemoKey = `required_${node.props.definition.schemaMemoKey}`

from formkit.

coatesjonathan avatar coatesjonathan commented on June 24, 2024

As a workaround ( not sure what the full implications it is yet ) you can remove the line:

node.props.definition.schemaMemoKey = `required_${node.props.definition.schemaMemoKey}`  

Yeah this works as a fix, but does this have a knock on effect?

from formkit.

fenilli avatar fenilli commented on June 24, 2024

tbf I'm not sure how schemaMemoKey works this smart guy might know more -> @justin-schroeder

from formkit.

coatesjonathan avatar coatesjonathan commented on June 24, 2024

Awesome thanks @justin-schroeder this fixes it perfectly! :)

from formkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.