Giter Site home page Giter Site logo

Comments (5)

xpepermint avatar xpepermint commented on July 20, 2024 1

Hum... it seams that Vue is not tracking changes on class instances but it could also be a bug in the plugin. I'll investigate so don't worry, we'll find a solution soon. I also asked for help here so please be patient.

from vue-rawmodel.

xpepermint avatar xpepermint commented on July 20, 2024

I'm about to start writing an example for you. I just need some information:

  • How does your form structure look like?
  • Are you using sub-components in your form?

from vue-rawmodel.

michaelsorich avatar michaelsorich commented on July 20, 2024

Thanks - this would be much appreciated.

I currently have a single component which focuses on editing the model (including its nested models). The template contains a single form containing simple fields of the parent model (using html input fields with v-model to bind the appropriate field similar to the example in the vue-contextable README.md), as well fields for each nested models in the array holding the nested models. I have been displaying the same set of fields for each instance of the nested model by iterating over nested models in the array using v-for (at the moment I have each nested model displayed as a row of a table). Next to the collection of fields for each nested model I have button to delete the nested model from the array (delete row from the table). I also have button to add an new nested model to the end of the array (i.e. add row to the bottom of the table in the form).

from vue-rawmodel.

xpepermint avatar xpepermint commented on July 20, 2024

Here is what I came up with:

  1. Since Vue.js doesn't recommend modifying a model structure at runtime, the easiest solution to fix this immediatelly is to set the defaultValue of each nested field to a non-null value as shown in the example below. This will deeply construct model structure before making the model reactive.
export default new Schema({
  fields: {
    ...
    book: {
      type: bookSchema,
      defaultValue: {} // THIS
    },
    books: {
      type: [bookSchema],
      defaultValue: [{}] // THIS
    }
  }
});
  1. I've upgraded this plugin with a new modelData configuration option which pre-populates a model (preferred way).
export default {
  contextable: {
    validate: [
      { 
        ...
        modelData: {},
      }
    ]
  },
  ...
}
  1. Two new reactive methods are also available - $build and $populate.
// using the $build method
export default {
  contextable: {
    ...
  },
  beforeCreate () {
    this.user.book = {title: 'asdasd'}; // sets field's data but removes reactivity
    this.user.books = [{title: 'asdasd'}]; // sets field's data but removes reactivity
    this.user.$build(); // rebuilds model reactivity
  }
}
// using the $populate method
export default {
  contextable: {
    ...
  },
  beforeCreate () {
    this.user.$populate({ // sets model fields and runs $build method
      name: null,
      book: {},
      books: [{}]
    });
  }
}
  1. The new $build method will help you build a form with dynamic fields as well. See the example for details.

Features have been published and a new version of this package is now available for download. Please let me know if this works for you.

from vue-rawmodel.

kristianmandrup avatar kristianmandrup commented on July 20, 2024

Cool :)

from vue-rawmodel.

Related Issues (13)

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.