Reset form after submit when transforming data #434
-
| Hello all! data() {
    return {
      imagesArray: [],
      featureImage: "",
      imagesPath: this.data.images_path,
      removePhotos: [],
      form: this.$inertia.form({
        _method: "PUT",
        title: this.data.title,
        nnumber: this.data.nnumber,
        description: this.data.description,
        is_premium: this.data.is_premium,
        rate: this.data.rate,
      }),
    };
  },and a method to submit the form:     updateAirplaneInformation(id) {
      this.form
        .transform((data) => ({
          ...data,
          remove_photos: this.removePhotos,
          images_path: this.imagesArray,
          img_path: this.featureImage,
        }))
        .post(route("airplanes.update", id), {
          preserveScroll: true,
        });
    },Thank you all in advance! | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
| @talelmishali The form helper also has some of the Inertia event callbacks like  updateAirplaneInformation(id) {
    this.form
        .transform(data => ({
            ...data,
            remove_photos: this.removePhotos,
            images_path: this.imagesArray,
            img_path: this.featureImage,
        }))
        .post(route('airplanes.update', id), {
            preserveScroll: true,
            onSuccess: page => {
                // Clear your array here
            },
        });
}, | 
Beta Was this translation helpful? Give feedback.
@talelmishali The form helper also has some of the Inertia event callbacks like
onSuccess. This should work: