1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

EmailJS, success/error - handlers, how to empty fields?

Discussion in 'JavaScript' started by iago111, Jan 31, 2021.

  1. #1
    Hello,
    I have implemented EmailJS for a contact form. I also use vue.js, but my questions is more directly JS related (not vue specific and/or EmailJS specific)

    I send an Email with the EmailJS function send. Everything works fine. (EmailJS works fine, vue works fine no problems here!!) I use a promise fo the http request.

    I have a little problem here. I can empty the fields with e.target.reset() at the end of the promise. Right now I have the reset outside the handlers. So the data is sent -> the fieds are emptied, the messages comes back, now the fields are filled again!!

    I guess I should bring e.target.reset() somehow into the .then or .catch block?
    How could I handle this, that the fields stay empty?

     methods: {       
              sendEmail(e) {
    
                const emailParams = {
                  uname: this.uname,
                  email: this.email,
                  message: this.message
    
                };
    
                emailjs.send('service_1234','template_1234', emailParams, 'user_1234')
                .then((result) => {
    
                    this.successHttpMsg = true;
                    console.log('SUCCESS!', result.status,result);
               
            }).catch((e) => {
               
                 this.error = e; 
                 this.errorHttpMsg = true;         
                  console.log("Caught",this.error);
               
            });
            e.target.reset();
            },
    Code (JavaScript):
    Thanks a lot guys!
     
    iago111, Jan 31, 2021 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #2
    My advice would be to pitch that junk in the trash. It doesn't work when client side scripting is disabled, meaning it's in violation of accessibility minimums, meaning it's a giant middle finger to a lot of users who might want to use your contact form!
     
    deathshadow, Feb 3, 2021 IP
  3. iago111

    iago111 Member

    Messages:
    99
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    33
    #3
    To be honest, what I like about these JS libraries and all that JS stuff (also node+express), is, that you can stick to ONE programming language and with that also ONE programming paradigm!

    I'm not so concerned about the users who have disabled JS but about the fact that SEO does not work very good with SPAs. But I haven't done anything conerning SEO yet.
     
    Last edited: Feb 4, 2021
    iago111, Feb 4, 2021 IP
  4. iago111

    iago111 Member

    Messages:
    99
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    33
    #4
    react.js is used by:
    Facebook, Instagram, Twitter, Netflix, WhatsApp, Dropbox, Salesforce, Reddit, Cloudflare, GitHub, Paypal, Uber, Zendesk

    angular.js is used by:
    Microsoft, Deutsche Bank, Google, Upwork, Paypal, Delta, Santander

    vue.js is used by:
    booking.com, Google, Adobe, BMW, Trustpilot, Netflix, Grammarly

    Why would you recommend to build projects without JS or with vanillaJS only?
     
    iago111, Feb 27, 2021 IP
  5. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    818
    Best Answers:
    7
    Trophy Points:
    320
    #5
    It is quite simple. Whenever a user voluntarily disables JS or is MANDATED to disable JS, such websites become INACCESSIBLE to the user. The ONLY valid reason to use JS is to ENHANCE a WORKING website. Anything else can and does BREAK LAWS in MANY countries and CAN result in fines of TENS OF THOUSANDS OF DOLLARS per DAY.
     
    mmerlinn, Feb 27, 2021 IP
  6. iago111

    iago111 Member

    Messages:
    99
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    33
    #6
    When you deactivate JS, Facebook does not even show a warning sign! It's just a blank page.
    But good call man, good call! :)

    So I have voluntarily disabled JS and this was the result!
     
    iago111, Feb 28, 2021 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #7
    And facebook has been lucky they haven't had their pants sued off... but given their lack of brick and mortar presence and more importantly their lack of products or services they are barely able to fly under the radar.

    You pull that stunt with a business actually selling something, or medical care, or government services, you're looking at that thousands in fines daily if the site does that.

    When who can be targeted, where, and for what is kind of up in the air depending on country and social mood, it's better to err on the side of caution than to blindly hope you avoid notice.

    1) I don't fall for the propaganda techniques known as bandwagon or testimonial. If all the other lemmings go running off a cliff...

    2) See how many companies you listed are using more than one framework of types that are kind-of supposed to do the same thing? Do you see the problem with this in terms of "simple"?

    3) I do not see ANY of these systems as simpler, easier, or better. In any way, shape, or form. The BEST you can say about them is that people have been conned into THINKING they are such because they use the words, but it's ALL BALD FACED LIES!!!

    They are more to learn on top of the underlying languages. They provide out of the box little in the way of USEFUL functionality that doesn't already exist in said languages or couldn't be implemented far, far, FAR better in a fraction the code. They often replicate things that already exist "because". They make you write as much if not more code than you'd have without them for any practical application, WITHOUT counting the size of their libraries against them. They make you use fat bloated libraries to do things that don't warrant libraries. Often things that don't even warrant the PRESENCE of JavaScript... or at most six lines to do what the library takes a dozen or more.

    They are popular and used out of ignorance, and propaganda that exploits same. ALL of the claims of being "easier" or "better for collaboration" or "faster" are as big if not bigger bunch of fictional whackjob fairy tales as the Easter bunny, Santa Clause, and Jesus.
     
    deathshadow, Mar 1, 2021 IP
  8. iago111

    iago111 Member

    Messages:
    99
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    33
    #8
    I'm sure that it is like that.
    But where do you want to start? Principally you cannot use ES6 because it does not run in older browsers, and ES6 is part of the core language.

    Then the libraries: I mean, every language makes use of libraries. Can you code one line of code in Java or Python without a library?
    I mean you can, but who does that?
     
    iago111, Mar 4, 2021 IP
  9. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #9
    This is 2021. F*** IE. F*** chakra based Edge. Four to five years ago, I'd agree, it wasn't "real world deployable". But we can't keep bending over backwards for browsers not even supported by the people who created them!. Edge is now a Chrome-like. IE is now hidden on new installs of windows 10.

    Even Microsoft is telling IE and Edge 12-18 users to go suck an egg this year.
    https://www.theverge.com/2020/8/17/...ernet-explorer-11-support-end-365-legacy-edge

    My current plan for dealing with IE is pretty simple. I tell HTML 5 validation to go plow itself by setting:

    
    <meta
    	http-equiv="X-UA-Compatible"
    	content="IE=9"
    >
    
    Code (markup):
    Don't even get me STARTED about how F***TARDED the W3C's current specification about the X-UA meta is.

    What this does is make IE11 behave like IE9, including turning back on conditional comments.

    Then for my stylesheets:

    
    <!--[if !IE]>-->
    	<link
    		rel="stylesheet"
    		href="screen.css"
    		media="screen"
    	>
    <!--<![endif]-->
    
    Code (markup):
    And my scripts:

    
    <!--[if !IE]>-->
    	<script src="template.js"></script>
    <!--<![endif]-->
    
    Code (markup):
    So legacy IE users get just the vanilla markup with no style or scripting. You use CSS and JS properly, the page should still be USABLE... it's not pretty, it might not have the scripting bells and whistles, but if someone INSISTS on trying to use it, it should still be usable.

    Why? Because for accessibility reasons a well written page should be able to gracefully degrade JS off, CSS off, images off. I've said it time and time again: progressive enhancement to provide graceful degradation. It's why HTML, CSS, and JS are implemented the way they are and is the entire flipping point of using HTML in the first place!

    Though if you must know what you can and cannot use, there's always:
    https://caniuse.com

    It also helps that MDN before they fired everyone working on their reference, added compatibility tables and links to caniuse. There's a reason I say "don't be a W3Fool, go to MDN".

    C programmers, assembly language programmers... people working in languages where the system functions are built in like JavaScript.

    Libraries can be good, helpful, and in crippled languages (like Java) even provide base functionality. The problem seems to be when they "graduate" to becoming a "framework'. It seems the defining characteristic of "frameworks" is to replicate what the language can already do, in as convoluted and pointless a way as possible, whilst changing how the language works in such a way nubes and rubes can be suckered into only knowing the framework, and not even understanding enough of the underlying language to realize how badly they're being saddled up and taken for a ride.

    It really doesn't help though that so many of these frameworks, libraries, api's, what-have-you are written by people who don't know enough HTML or CSS to be writing JavaScript yet.
     
    deathshadow, Mar 6, 2021 IP
  10. iago111

    iago111 Member

    Messages:
    99
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    33
    #10
    You know what, I think I go back to Java, my idea was to programm virtual navigational instruments for yachts (a friend of mine is a skipper so I know a littel bit about this).
    I don't get anything done with HTML, CSS + JS!!
    From an conceptual point of view, I need COMPONENTS for that (e.g. clock displays, digital displays) and these components must be

    REUSABLE AND EASEY TO USE!

    Because the maths behind all this is quite demanding even for small sized simulations!
     
    iago111, Mar 10, 2021 IP