Skip to content

Commit 764c556

Browse files
committed
autoform integration
1 parent e97c25b commit 764c556

14 files changed

+86
-624
lines changed

README.md

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ Schemas.Posts = new SimpleSchema({
4949
afFieldInput: {
5050
type: 'fileUpload',
5151
collection: 'Images',
52-
label: 'Choose file' # optional
5352
}
5453
}
5554
}
@@ -76,7 +75,7 @@ or
7675
{{/autoForm}}
7776
```
7877

79-
### Multiple images
78+
### Multiple images //does not support yet
8079
If you want to use an array of images inside you have to define the autoform on on the [schema key](https://github.com/aldeed/meteor-simple-schema#schema-keys)
8180

8281
```javascript
@@ -100,33 +99,7 @@ Schemas.Posts = new SimpleSchema({
10099
})
101100
```
102101

103-
### Customization
104-
You can customize the button / remove text.
105-
106-
Defaults:
107-
```
108-
{{> afFieldInput name="picture" label="Choose file" remove-label="Remove"}}
109-
```
110-
111-
Also it is possible to customize accept attribute
112-
113-
add it in your schema definition:
114-
```javascript
115-
picture: {
116-
type: String,
117-
autoform: {
118-
afFieldInput: {
119-
type: 'fileUpload',
120-
collection: 'Images',
121-
accept: 'image/*',
122-
label: 'Choose file' # optional
123-
}
124-
}
125-
}
126-
127-
```
128-
129-
### Custom file preview
102+
### Custom file preview /// need to work on this
130103

131104
Your custom file preview template data context will be:
132105

@@ -151,61 +124,3 @@ picture: {
151124
<a href="{{file.url}}">{{file.original.name}}</a>
152125
</template>
153126
```
154-
155-
### Custom select/remove file buttons
156-
157-
Remember to add `js-af-select-file` and `js-af-remove-file` classes to nodes which should fire an event on click.
158-
159-
```javascript
160-
picture: {
161-
type: String,
162-
autoform: {
163-
afFieldInput: {
164-
type: 'fileUpload',
165-
collection: 'Images',
166-
selectFileBtnTemplate: 'mySelectFileBtn',
167-
removeFileBtnTemplate: 'myRemoveFileBtn'
168-
}
169-
}
170-
}
171-
```
172-
173-
```html
174-
<template name="mySelectFileBtn">
175-
<button type="button" class="js-af-select-file">Upload file</button>
176-
</template>
177-
178-
<template name="myRemoveFileBtn">
179-
<button type="button" class="js-af-remove-file">Remove</button>
180-
</template>
181-
```
182-
183-
### Callbacks
184-
185-
**onBeforeInsert** - can be used to modify file (remember to return fileObj)
186-
187-
**onAfterInsert** - called after insert with two arguments: error object and file object
188-
189-
Please note that callback properties are functions that return callbacks. This is because autoform evaluates function attributes first.
190-
191-
```javascript
192-
picture: {
193-
type: String,
194-
autoform: {
195-
afFieldInput: {
196-
type: 'fileUpload',
197-
collection: 'Images',
198-
onBeforeInsert(fileObj) {
199-
fileObj.name = 'picture.png';
200-
fileObj
201-
},
202-
onAfterInsert(err, fileObj) {
203-
if err
204-
alert 'Error'
205-
else
206-
alert 'Upload successful'
207-
}
208-
}
209-
}
210-
}
211-
```

lib/client/autoform-file.coffee

Lines changed: 0 additions & 122 deletions
This file was deleted.

lib/client/autoform-file.html

Lines changed: 0 additions & 42 deletions
This file was deleted.

lib/client/autoform-file.less

Lines changed: 0 additions & 44 deletions
This file was deleted.

lib/client/autoform.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
AutoForm.addInputType("fileUpload", {
2+
template: "afFileUpload",
3+
});

lib/client/fileUpload.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template name="afFileUpload">
2+
<input value="{{fileId}}" type="hidden" {{this.atts}}>
3+
{{#if $gt uploadedFile.count 0}}
4+
{{#each uploadedFile}}
5+
<div>
6+
{{> uploadImageDemo}}
7+
</div>
8+
<a data-action="remove-file">Remove</a>
9+
{{/each}}
10+
{{else}}
11+
{{#if currentUpload}}
12+
{{#with currentUpload}}
13+
Uploading <b>{{file.name}}</b>:
14+
<span class="progress">{{progress}}%</span>
15+
{{/with}}
16+
{{else}}
17+
<input class="form-control af-file-upload-capture" type="file"/><!-- ability to add accept="image/*" capture="camera"-->
18+
{{/if}}
19+
{{/if}}
20+
</template>

0 commit comments

Comments
 (0)