Skip to content

Commit b08cd78

Browse files
committed
Fix #41: Add new config variable fileHandlerArgs
Now we can get rid of Django specific keywords from the library.
1 parent 3679b56 commit b08cd78

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

src/components/form.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,10 @@ export class FormFileInput extends React.Component {
410410
this.setState({loading: true});
411411

412412
let formData = new FormData();
413-
formData.append('field_name', this.context.fieldName);
414-
formData.append('model_name', this.context.modelName);
413+
for (let key in this.context.fileHandlerArgs) {
414+
if (this.context.fileHandlerArgs.hasOwnProperty(key))
415+
formData.append(key, this.context.fileHandlerArgs[key]);
416+
}
415417
formData.append('coords', getCoordsFromName(this.props.name));
416418
formData.append('file', e.target.files[0]);
417419

src/components/uploader.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ export default class FileUploader extends React.Component {
135135
let endpoint = this.props.handler || this.context.fileHandler;
136136

137137
let querystring = new URLSearchParams({
138-
field_name: this.context.fieldName,
139-
model_name: this.context.modelName,
138+
...this.context.fileHandlerArgs,
140139
coords: getCoordsFromName(this.props.name),
141140
trigger: trigger
142141
});
@@ -231,8 +230,7 @@ export default class FileUploader extends React.Component {
231230
<LibraryPane
232231
fileHandler={this.props.handler || this.context.fileHandler}
233232
fileHandlerArgs={{
234-
field_name: this.context.fieldName,
235-
model_name: this.context.modelName,
233+
...this.context.fileHandlerArgs,
236234
coords: getCoordsFromName(this.props.name),
237235
}}
238236
onFileSelect={this.handleFileSelect}

src/form.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ export default class ReactJSONForm extends React.Component {
125125
<EditorContext.Provider
126126
value={{
127127
fileHandler: this.props.fileHandler,
128-
fieldName: this.props.fieldName,
129-
modelName: this.props.modelName,
128+
fileHandlerArgs: this.props.fileHandlerArgs,
130129
}}
131130
>
132131
{this.getFields()}

src/renderer.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ export function FormInstance(config) {
1313
this.data = config.data;
1414
this.errorMap = config.errorMap;
1515
this.fileHandler = config.fileHandler;
16-
this.fieldName = config.fieldName;
17-
this.modelName = config.modelName;
16+
this.fileHandlerArgs = config.fileHandlerArgs || {};
1817

1918
this.eventListeners = null;
2019

@@ -58,8 +57,7 @@ export function FormInstance(config) {
5857
data={this.data}
5958
errorMap={this.errorMap}
6059
fileHandler={this.fileHandler}
61-
fieldName={this.fieldName}
62-
modelName={this.modelName}
60+
fileHandlerArgs={this.fileHandlerArgs}
6361
onChange={this.onChange}
6462
/>,
6563
document.getElementById(this.containerId)
@@ -175,8 +173,7 @@ export class FormContainer extends React.Component {
175173
editorState={this.state.editorState}
176174
onChange={this.handleChange}
177175
fileHandler={this.props.fileHandler}
178-
fieldName={this.props.fieldName}
179-
modelName={this.props.modelName}
176+
fileHandlerArgs={this.props.fileHandlerArgs}
180177
errorMap={this.props.errorMap}
181178
/>
182179
);

0 commit comments

Comments
 (0)