Comments (5)
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.
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.
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.
Here is what I came up with:
- 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
}
}
});
- I've upgraded this plugin with a new
modelData
configuration option which pre-populates a model (preferred way).
export default {
contextable: {
validate: [
{
...
modelData: {},
}
]
},
...
}
- 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: [{}]
});
}
}
- 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.
Cool :)
from vue-rawmodel.
Related Issues (13)
- Example on loading data into model HOT 4
- How to set up a date field properly? HOT 4
- Shared client and server side validation models HOT 7
- Nested models and reactivity
- Update for current rawmodel? HOT 3
- Required if validator HOT 6
- Saving only changed and valid fields HOT 4
- Docs for use with server rendering HOT 2
- Using Vuex HOT 1
- new API and renaming from vue-contextable to vue-rawmodel
- Decorator support HOT 2
- Any way to check if the field is dirty? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-rawmodel.