Extended 'file' custom widget doesn't get the uploaded file
See original GitHub issueDescribe the bug
I am extending the file
widget through getWidget('file')
to achieve some custom validation of an uploaded .json. After some guessing/research I found out just class components are supported:
import CMS from 'netlify-cms-app'
import React, { PureComponent } from 'react'
const FileControl = CMS.getWidget('file')
class JSONControl extends PureComponent {
isValid = () => ({ error: { message: 'Your error message.' } })
render() {
return <FileControl.control {...this.props} />
}
}
export default JSONControl
To Reproduce When I try to upload a file after clicking “choose file” and selecting it from the media library (uploads successfully) it doesn’t get assigned as value to the field and the field still shows “choose file” as if nothing happened.
Expected behavior
My aim here is to upload such file and on “publish” perform the isValid
validation that I will implement. Therefore I need to have access to the file.
Applicable Versions: netlify-cms-core 2.12.1 netlify-cms-app 2.9.6
CMS configuration The relevant CMS config for that file is:
{
label: 'JSON',
name: 'JSON',
widget: 'JSON',
},
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Custom widget Image upload Issue - Stack Overflow
In that widget, have an image upload field with some other fields. I have done everything and the widget is working very well...
Read more >Custom widget doesn't appear in list - PTC Community
Hi, I recently created a custom widget according with the documentation. The strcuture is : schemaW.zip => metadata.xml => ui/ =>
Read more >Creating the file uploader widget on a page. Webix Docs
Webix Documentation: Learn how to allow users uploading files to a server with the file uploader. The page contains detailed guides describing the ......
Read more >Custom Widgets - FlutterFlow Docs
Using our custom widget editor, you can add any widget to your project. You can write/modify the widget code or upload it directly...
Read more >Chapter 9 Uploads and downloads - Mastering Shiny
9.1.3 Uploading data · input$upload is initialised to NULL on page load, so you'll need req(input$upload) to make sure your code waits until...
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 Free
Top 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
@sleepingkiwi FYI, I’m actually refactoring the way the CMS is handling assets as a part of https://github.com/netlify/netlify-cms/issues/1472.
There are numerous bugs related to assets not shown in the CMS UI as they have not been published yet to the site: https://github.com/netlify/netlify-cms/issues/2953 https://github.com/netlify/netlify-cms/issues/1750 https://github.com/netlify/netlify-cms/issues/2332 https://github.com/netlify/netlify-cms/issues/2516
In short the
getAsset
will try to retrieve the asset from the UI state and fallback to get it from the repo (and not the published site). That meant changinggetAsset
to return a promise that resolves with the asset url instead of just a string.Fantastic, thanks for your work on that @erezrokah I think that’s exactly how I’d want getAsset to work for our use cases. I’m excited to see that land!