Click here to Skip to main content
15,881,742 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Relation between null and zero. Pin
Richard Deeming24-Sep-18 8:03
mveRichard Deeming24-Sep-18 8:03 
GeneralRe: Relation between null and zero. Pin
GKP199224-Sep-18 17:37
professionalGKP199224-Sep-18 17:37 
QuestionTypeScript, Dropping Image and loading preview without posting, a working sample, FileReader, readAsDataUrl, reader.result Pin
jkirkerx19-Sep-18 7:55
professionaljkirkerx19-Sep-18 7:55 
QuestionCan't match this string in typescript using if and else if Pin
jkirkerx18-Sep-18 13:04
professionaljkirkerx18-Sep-18 13:04 
AnswerRe: Can't match this string in typescript using if and else if Pin
Graham Breach18-Sep-18 21:21
Graham Breach18-Sep-18 21:21 
GeneralRe: Can't match this string in typescript using if and else if Pin
jkirkerx19-Sep-18 7:27
professionaljkirkerx19-Sep-18 7:27 
QuestionCan't match this string in typescript using if and else if Pin
jkirkerx18-Sep-18 13:04
professionaljkirkerx18-Sep-18 13:04 
QuestionHow to cancel a drag event Pin
jkirkerx18-Sep-18 9:25
professionaljkirkerx18-Sep-18 9:25 
This is for my Angular 6 training, in which I'm making a back end SPA for creating a Portfolio of work.
I'm writing this in TypeScript and not JavaScript, because it will just get compiled into JavaScript anyways.

So if a user selects more than one image file, or if the file is not an image file, I would like to cancel the event and send a message.

I've never done this before, or have had a drag and drop event canceled on me in the past using other web sites, so I have no creative ideas on what type of signal or alert to use.

Right now I'm using event.preventDefault() but it doesn't really do anything. I can still drop the files.
And I'm turning the drop target border red which works.
onDragOver(event: any) {

    event.preventDefault();
    event.stopPropagation();
    event.target.style.opacity = '0.4';        

    // Grab the files selected being dragged over
    let files = event.target.items || event.dataTransfer.items;

    // Cancel the Operation if the user tries to drag more than one file.
    // Or if the file type is not a JPEG or PNG
    if (files.length > 1) {
        event.target.style.border = 'dashed 3px #EE6363';
        event.preventDefault();
        console.log('drag canceled for too many files');
        return false;
    }
    else if (files[0].type !== 'image/jpeg' || files[0].type !== 'image/png') {
        event.target.style.border = 'dashed 3px #EE6363';
        event.preventDefault();
        console.log('drag canceled for not being an image file');
        return false;
    }

    console.log('dragged files', JSON.stringify(files, null, 2));
    console.log('dragged file count', JSON.stringify(files.length, null, 2));

}
If it ain't broke don't fix it
Discover my world at jkirkerx.com


modified 18-Sep-18 15:35pm.

AnswerRe: How to cancel a drag event Pin
Richard Deeming18-Sep-18 10:53
mveRichard Deeming18-Sep-18 10:53 
GeneralRe: How to cancel a drag event Pin
jkirkerx18-Sep-18 11:54
professionaljkirkerx18-Sep-18 11:54 
Questioncouldn't read from datalist Pin
thepast16-Sep-18 21:01
thepast16-Sep-18 21:01 
QuestionHow to pass JavaScript output to an HTML String Variable outside the <script>? Pin
Member 1348136115-Sep-18 15:45
Member 1348136115-Sep-18 15:45 
AnswerRe: How to pass JavaScript output to an HTML String Variable outside the <script>? Pin
Richard Deeming18-Sep-18 3:45
mveRichard Deeming18-Sep-18 3:45 
QuestionTrouble uploading files with aws s3 Pin
Member 1398382813-Sep-18 13:15
Member 1398382813-Sep-18 13:15 
AnswerRe: Trouble uploading files with aws s3 Pin
jkirkerx1-Oct-18 8:04
professionaljkirkerx1-Oct-18 8:04 
Questiongetting error period.draggable is not a function Pin
Gopal Kan12-Sep-18 19:49
Gopal Kan12-Sep-18 19:49 
AnswerRe: getting error period.draggable is not a function Pin
Graham Breach12-Sep-18 21:08
Graham Breach12-Sep-18 21:08 
QuestionModal popup with datalist Pin
thepast12-Sep-18 8:18
thepast12-Sep-18 8:18 
QuestionJavascript and extensions Pin
Member 1398114211-Sep-18 15:10
Member 1398114211-Sep-18 15:10 
QuestionWhen pressing right and left keys object not moving in javascript game. Pin
Member 1396097131-Aug-18 11:10
Member 1396097131-Aug-18 11:10 
QuestionAngular 6, lazy loading, with routerLink="/reviews" it works, type the Url localhost:5000/reviews and page not found Pin
jkirkerx17-Aug-18 13:06
professionaljkirkerx17-Aug-18 13:06 
AnswerRe: Angular 6, lazy loading, with routerLink="/reviews" it works, type the Url localhost:5000/reviews and page not found Pin
jkirkerx18-Aug-18 13:31
professionaljkirkerx18-Aug-18 13:31 
General[Solved] Pin
jkirkerx20-Aug-18 9:25
professionaljkirkerx20-Aug-18 9:25 
QuestionCoding Newbie Pin
Rokas Steiblys17-Aug-18 10:21
Rokas Steiblys17-Aug-18 10:21 
AnswerRe: Coding Newbie Pin
Richard MacCutchan17-Aug-18 21:37
mveRichard MacCutchan17-Aug-18 21:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.