Formik custom file upload gives InvalidStateError - react-bootstrap

I'm using react-bootstrap custom file upload. Want to validate, that input is not empty and type of the file is video. Using react-bootstrap custom file upload it doesnt give me any error message on empty form. With the basic one it does. When i upload some it gives me InvalidStateError: The object is in an invalid state. Here it is in sandbox. The commented lines are for the basic file input.

I think the issue is related to the value prop of Form.File, you can't render a File.
If you change it to: value={values.file?.filename || ""} it seems to work fine.

Related

Put request in POSTMAN, laravel

I am using the postman for an api creation for my laravel project.
I have made POST requesting for uploading the video but now I am trying to make a PUT request.Other things are being updated in the table using it like title and name but I am not able to use any option to upload the file(image) for PUT request.And if I use form-data then nothings happens in this case.
You should be required the following changes.
1) In Headers
The Content-type field has been set as multipart/form-data in Headers.
2) Choose the File option instead of text from the dropdown on the right side.
3) add _method: PUT in form-data
For PUT calls, try adding data in x-www-form-urlencoded
You need to use POST method for file uploading. cause PUT method not supporting file uploading. here is issue in official github repo of laravel. you can see here reply from laravel
If using formdata, add this Key: _method and value: PUT, in the formdata. Then use POST as the request.
NB: This also supports Image uploading, give the key the name you want, then change text to File
select form-data and select file type from the key box and change Text to File.
In postman, you can simply send a PUT request by changing the Request method near URL Bar.
For uploading files, select "form-data" as input in postman then you will see a panel to enter key-value pairs. Initially, you will notice that both the fields take text as input.
To upload a file from this panel, in the left box (where you are supposed to enter key name) check the rightmost corner. You can see the type of the box and then change it to file.
As soon as you change the key type, the value field will ask you to upload a file.
Edit 1:
You can see in the screenshot here, where you need to change it from "Text" to "File"
What you need to do is just:
Select POST method
Set _method = PUT in the body of Form-data

TinyMCE4 `image_list` external url

I am trying to get TinyMCE 4's image_list to work with a URL returning JSON data as specified in the example here.
I have setup a GET endpoint http://demo.com/media on my server which gives back a JSON response consisting of a list of objects with their title and value attributes set, for example:
[{"title":"demo.jpg","value":"http://demo.com/demo.jpg"}]
I have also specified the option image_list: "http://demo.com/media" when initializing the plugin.
However, when I click the image icon in the toolbar, nothing pops up. All I can see in the network tab is an OPTIONS request with status 200, but then nothing. The GET request I was expecting never happens.
What is the correct way of using image_list in TinyMCE 4? Also, does anyone have a working demo example? I couldn't find anything.
It is somewhat hard to say what the issue is without seeing the exact data your URL is returning. I have created a TinyMCE Fiddle to show (in general) how this is supposed to work:
http://fiddle.tinymce.com/pwgaab
There is a JavaScript variable at the top (pretendFetchedData) that simulates what you would grab from the server (an array of JavaScript objects) and that is referenced via image_list.
If you enter your URL (http://demo.com/media) into a browser window what is returned? Are you sure its an array of JavaScript objects?
I have the identical problem. No matter what I do with the detail of the format (e.g. putting quotes round title and value), nothing happens.
I guess the only way (for me anyway) is to insert the list into the script with php before sending the web page.

unusual error occur in laravel validation

In my laravel 4 project i gave a validation like this
'contact_no' => 'numeric|digits_between:10,10',
But this shows error in a weird situation. If I copy and paste the phone number in the field it shows validation error "The contact no must be a number." But when I type the phone number everything is fine.
Did anyone knows why laravel shows this kind of error? and how I can resolve this?
The screen shot is:
If you copy a string from a source which is not plain text (but formated text) sometimes there are invisible spaces copied along with the string. I had this strange behavior several times.
How you test it
Open notepad (or any plain text editor)
Type your number
Copy it from there
Paste it in your form
I guess this number will work.
How you could try to go around this problem
Before validation trim the input data from contact_no to remove all whitespaces first. See http://php.net/manual/en/function.trim.php

Knockout set initial value of an input field where html is allowed

I have two input fields first name and last name.
Application was running really well.
Suddenly someone came in from Mars and input something like this in those input fields
*(~'##~>?<+!""*%$)!
for both first name and last name. Now don't ask me why he did this cause in Mars this is very common. You can try it on this fiddle
http://jsfiddle.net/farrukhsubhani/3RjRF/
This text then went into my database and now when i retrieve it it came back like this
*(~'##~>?<+!""*%$)
which is ok for me as its html and I can place it back into knockout and it gets populated as html as you can see in fiddle above. However this Mars guy then thought that on Earth this is not a nice name to be with so he tried to edit field.
The above fiddle is kind of that edit page which shows him old value at bottom and two fields at top. He does not know html so he thought we have changed his name in input fields however I need to know
When passing text to knockout to give initial value to an input field is it possible to tell it that consider this text as html so it renders properly in input field
The other way around is to send him to http://www.w3schools.com/tags/ref_entities.asp and tell him about reserved HTML characters. This info has been stored in database (using Entity Framework simple person.fname and person.lname both with attribute AllowHTML) so on my fiddle i have just placed it in two variables and you can see how actual text boxes are different than html below. If i dont bind using Knockout then actual text is shown in these boxes and user can edit <>' signs without any problem.
Anyone with a solution before he leaves our planet. This can change alien life on our planet.
Update
If i go into this field and paste (~'##~>?<+!""*%$)" binding works fine and you can copy this and paste it into fiddle to see that. However its not taking that value from Javascript variable to knockout expects it to be a string and html special characters are not shown properly in input field.
We have done another test without Knockout and this text does get rendered within the field when you try to edit it its fine.
We have updated JSfiddle to work without JQuery and its the same result if you store it in a js variable and give not value to input field
http://jsfiddle.net/farrukhsubhani/3RjRF/3/
If we assign value to input field and just use jQuery to populate fullname then it works
http://jsfiddle.net/farrukhsubhani/3RjRF/4/
This last fiddle is a working example and we want Knockout to do what JQuery is doing.
I think the question then comes to how can this text be stored in javascript variable and placed into input field as html text so special characters appear unescaped. You can try unescape on jsfiddle that did not work for us.
Somewhere along the trip into (or maybe out of) your database, the value is being HTML-escaped. It's not Knockout itself that's doing it. You're going to need to track that location down, but you can't just disable it; you're going to have to replace it with something that sanitizes the result or otherwise you're opening yourself up to cross-site scripting attacks (any <script>s from external sources inserted into the input would have complete access to your data).
Any time you see the html: binding used, warning bells should go off in your head and you should VERY carefully to check to ensure that there's NO possibility of raw, unexamined user input making it into the string that gets displayed.
Ok here is what i did at the end
http://jsfiddle.net/farrukhsubhani/3RjRF/7/
I have done following:
I have added value attribute to input field and placed the input text as it came from server into it. Because I am using TextBoxFor in MVC it did that for me.
Before I apply knockout binding I have picked this value up using $('#kfname') and passed it to the actual binding so it used the value that came from server. Previously it was passed like (#Model.fname,#Model.lname)
I think what this did was allowed jQuery to pick up the value and assign it to binding instead of variable
ko.applyBindings(new ViewModel($("#kfname").val(), $("#klname").val()));
Hopefully this would help someone using knockout.

angular custom directive required validation is not updated

i created my own directive, replacing an input field with a custom made input field. However, the validation of the required field never seems to update and instead is always false.
Other directives inside my directive like ng-class do work.
I have created a plunker here to show this problem:
http://plnkr.co/edit/NuZNAJceL0MVX8i6RK9n?p=preview
Can anybody help me out how to make sure that the required validation is properly updated?

Resources