Passing data to widget?
See original GitHub issueHi,
i will use your great library to generate forms in an ionic app (ionicframework.com).
My template:
<sf-form
[schema]="schema"
[actions]="schemaActions"
[model]="myModel"
(onChange)="onChange($event)">
</sf-form>
Home component:
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
imageMetaData = {
imageName: '',
imagePath: ''
};
filename: string = 'test.jpeg';
myModel = { };
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"title": {
"label": "Title",
"type": "string",
"description": "Title"
},
"description": {
"label": "Description",
"type": "string",
"description": "Description",
"minLength": 6
},
image: {
"label": "Foto",
"type": "string",
"widget": "image",
"buttons": [{
"id": "takeFoto",
"block": true,
"outline": true,
"label": "Take a Foto!"
}]
}
},
"required": ["title", "description", "image"],
"buttons": [{
"id": "submit", // the id of the action callback
"label": "Submit" // the text inside the button
}],
"fieldsets": [{
"title": "General Information",
"fields": ["title", "description"]
}, {
"title": "Foto",
"fields": ["image"]
}
]
};
schemaActions = {
"takeFoto": () => {
this.takeFoto();
},
"submit": (form, options) => {
debugger;
}
}
constructor(public navCtrl: NavController,
private camera: Camera,
private file: File,
private toastCtrl: ToastController) {
}
onChange(event: Event) {
console.log(event);
}
takeFoto() {
//capturing foto on device and sets imagePath and imageName ...
this.imageMetaData.imagePath = ...;
this.imageMetaData.imageName = ...;
}
}
I created a new Widget:
template:
<ion-item>
<ion-label stacked>Name of file</ion-label>
<ion-input type="text"
[(ngModel)]="filename"
[formControl]="control"
[readonly]="true">
</ion-input>
</ion-item>
and the component:
export class IonImageWidget extends ControlWidget implements AfterViewInit {
filename: string;
constructor() {
super();
}
ngAfterViewInit() {
super.ngAfterViewInit();
//Only for testing
this.filename = 'filename.jpg';
}
}
- How can i access the json-model (myModel) if the form is „submitted"?
- How can i pass the file path and file name from the takeFoto() method to the Widget or do I have to put the „takeFoto logic“ into the widget itself?
- How can i update the json model to include the filename/path after capturing the foto?
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
Simple ways to pass to and share data with widgets/pages
The simplest way to send data from a widget to another is by its constructor. Let's say, for example, we need to pass...
Read more >Send data to a new screen - Flutter documentation
Navigate and pass data to the detail screen To capture the user's tap in the TodosScreen , write an onTap() callback for the...
Read more >Pass Data to Stateful Widget in Flutter : 3 Easy Steps (2022 ...
To pass data to stateful widget, first of all, create two pages. Now from the first page open the second page and pass...
Read more >The best way to passing data between widgets in Flutter
Show activity on this post. First, bear in mind that in Flutter data can only be passed downward. It is by design not...
Read more >Passing Data to Widget | Apple Developer Forums
I have an app coded with UIKit and want to add a simple Widget with Widgetkit. How can I pass the data to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
File inputs are now supported (see https://github.com/makinacorpus/angular2-schema-form/issues/41), it will be part of the next release.
I struggled extending a custom widget for a File Object instead of base64 as @big-r81 seems to have accomplished. For anyone else who might be struggling, I had to remove this line from the original FileWidget:
this.filedata.data = btoa(this.reader.result);
Here is my full extended file widget:
And this was the schema I used:
The data property then will house the File Object.
The issue I’m struggling with is being able to show the file if it already exists (a pdf for example or profile image). In this framework what would be the best way to go about doing that? Can you conditionally show buttons? Can you pass in values such as names to the description or file paths (urls)?