CtnChainsaw Posted June 27, 2013 Share Posted June 27, 2013 Hi all, I'm new to backbone and JQuery and I'm trying to get my head around it. I'm doing exercise 2 from this book: http://addyosmani.github.io/backbone-fundamentals/#getting-set-up It says "You may notice that the file input for the cover image isn’t working, but that is left as an exercise to the reader."I've tried uploading an image and I get this in the console: GET file:///C:/fakepath/dan_brown.jpg This should be easy enough to do. Anyone got any ideas? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/279636-backbone-newbie-question/ Share on other sites More sharing options...
CtnChainsaw Posted June 27, 2013 Author Share Posted June 27, 2013 This is happening when I'm using Chrome. I get the name of the file "dan_brown.jpg" when using Firefox. Quote Link to comment https://forums.phpfreaks.com/topic/279636-backbone-newbie-question/#findComment-1438216 Share on other sites More sharing options...
CtnChainsaw Posted June 27, 2013 Author Share Posted June 27, 2013 Something like this will do it. However all elements then have 'img/' prepended to the content because the first if statement evaluates to true each time. Anybody got any tips to sort this? addBook: function( e ) { e.preventDefault(); var formData = {}; $( '#addBook div' ).children( 'input' ).each( function( i, el ) { if( $( el ).val() != '' ) { if($("#coverImage").attr("name") == 'coverImage'){ formData[ el.id ] = 'img/' + $( el ).val(); } else if ($("#coverImage").attr("name") != 'coverImage') { formData[ el.id ] = $( el ).val(); } } }); this.collection.add( new app.Book( formData ) ); }, Quote Link to comment https://forums.phpfreaks.com/topic/279636-backbone-newbie-question/#findComment-1438225 Share on other sites More sharing options...
Solution CtnChainsaw Posted June 27, 2013 Author Solution Share Posted June 27, 2013 Sorted addBook: function( e ) { e.preventDefault(); var formData = {}; $( '#addBook div' ).children( 'input' ).each( function( i, el ) { if( $( el ).val() != '' ) { if( el.id === 'coverImage') { formData[ el.id ] = 'img/' + $( el ).val(); } else { formData[ el.id ] = $( el ).val(); } } }); this.collection.add( new app.Book( formData ) ); }, Quote Link to comment https://forums.phpfreaks.com/topic/279636-backbone-newbie-question/#findComment-1438230 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.