primefaces / primevue

Next Generation Vue UI Component Library
https://primevue.org
MIT License
10.64k stars 1.24k forks source link

Component Name: Form #6774

Open martin-obert opened 1 week ago

martin-obert commented 1 week ago

Bug description

Submiting form doesn't pass values in the event as described at your official docu https://primevue.org/forms/ Trying any official example via stackblitz yields same result: Submit example on your official site

const onFormSubmit = ({ valid, values }) => {
  console.log(values); /// <-- values are undefined

  if (valid) {
    toast.add({
      severity: 'success',
      summary: 'Form is submitted.',
      life: 3000,
    });
  }
};

Am I missing something? How do I get the actual submitted data?

Reproducer

https://stackblitz.com/edit/kcnxrq?file=src%2FApp.vue

PrimeVue version

4.2.1

Vue version

3.x

Language

TypeScript

Build / Runtime

Vue CLI App

Browser(s)

Chrome 90

Steps to reproduce the behavior

Click on Submit button and observe the browser console

Expected behavior

text from input field should appear in the console output

raizdev commented 1 week ago

Schema is required...

martin-obert commented 1 week ago

I've looked up for schema in the docs, but without luck. Can you please provide more details, what schema are you referencing to. Any code example?

Tjattex0 commented 1 week ago

Hello @martin-obert,

if you need to access values in the onFormSubmit method, ensure that your resolver returns both the values and errors, like this:

const resolver = ({ values }) => {
  const errors = {};

  if (!values.username) {
    errors.username = [{ message: 'Username is required.' }];
  }

  return {
    errors,
    values
  };
};

During form submission, the resolver first validates the form. A callback is then triggered, providing information about the form's current state (see the Form Submit section here). This callback is partially composed of the resolver’s return values and errors.