Code Monkey home page Code Monkey logo

Comments (7)

tjinauyeung avatar tjinauyeung commented on May 27, 2024

Hi subx, thanks for submitting an issue.

Can you give a code example of how you want to use it?

from svelte-forms-lib.

subpx avatar subpx commented on May 27, 2024

subpx/svelte-forms-lib-examples@55abfae

This is just a quick example to show the issue. The validation is working in this demo but would be much nicer to not need to manually create a fake DOM event

from svelte-forms-lib.

tjinauyeung avatar tjinauyeung commented on May 27, 2024

Thanks for the example; in this case I'll need to read up on Svelte events a bit before I can think of a solution.

However, please feel free to experiment and create a PR! I happily review it.

from svelte-forms-lib.

tjinauyeung avatar tjinauyeung commented on May 27, 2024

The most naive implementation I can think of

function isCustomEvent(event) {
  return event instanceof CustomEvent;
}

function handleChange(event) {
  let field;
  let value;

  if (isCustomEvent(event)) {
    field = event.detail.name;
    value = event.detail.value;
  } else {
    field = event.target.name;
    value = event.target.value;
  }

  // remaining handleChange code
}

Is this something that would solve your issue?

from svelte-forms-lib.

kbytesys avatar kbytesys commented on May 27, 2024

Yep, it could be usefull.

I'm wrapping the custom event at the moment:

export function wrapCustomChangeEvent(event) {
    return {
        target: {
            name: event.detail.name,
            value: event.detail.value
        }
    }
}

and I'm using this function this way in the svelte component:

on:change={(event) => handleChange(wrapCustomChangeEvent(event))}

I think it's better to use a different function name maybe: handleCustomEvent?

from svelte-forms-lib.

subpx avatar subpx commented on May 27, 2024

@tjinauyeung yes that is perfect.

from svelte-forms-lib.

tiaanduplessis avatar tiaanduplessis commented on May 27, 2024

I'm closing this issue as updateValidateField added by @kbytesys provides this ability to work with custom events.

from svelte-forms-lib.

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.