• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Input field forces restart instead of update

Scheduled Pinned Locked Moved Troubleshooting
3 Posts 2 Posters 1.1k Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    joncedimov
    last edited by Feb 9, 2018, 2:02 PM

    Hi, I’ve just recently started with using raspberry pi and started with magic mirror.
    I created a module through the template provided, with the use for adding an input field.

    I’ve been running into an issue of each time I press the enter key on the keyboard after entering a text in the filed or just having the empty field, the magic mirror restarts itself and I’m back to square one.

    This is the code to create it iside the getDom function:

    getDom: function() {
       var self = this;
       var wrapper = document.createElement("div");
       
       self.config.form = document.createElement("form");
       self.config.inputbox = document.createElement("input");
       self.config.dropdownFields = document.createElement("select");
        
        self.config.inputbox.setAttribute("type", "text");    
        
        self.config.form.appendChild(self.config.inputbox);
        self.config.form.appendChild(self.config.dropdownFields);
        wrapper.appendChild(self.config.form);    
       
    	// If this.dataRequest is not empty
    	if (this.dataRequest) {
                       self.getInput();
                       self.getFields();      
    	}
    
    	return wrapper;
    },
    

    Every time I hit enter it refreshes the whole page.

    I’ve also added code for action on change:
    self.config.inputbox.onchange = function() {self.setVisibile(self.config.dropdownFields)};
    but even without this code it still
    The good news is I can notice that the onchange function works (just before everything is restarted).

    Does anyone have any idea why this is like that, do I need to change some settings I am not aware of??

    Thank you for any feedback.

    N 1 Reply Last reply Feb 10, 2018, 2:57 AM Reply Quote 0
    • N Offline
      ninjabreadman @joncedimov
      last edited by Feb 10, 2018, 2:57 AM

      @joncedimov If it’s the [enter] causing problems, you may need to override/disable the onsubmit event listener for the form. It may be that you’re submitting the form, MM has no idea what to do with that data, and so simply displays (reloads) the same page.

      Problem with config or JavaScript? Copy/paste it into JSHint.
      Check out the detailed walkthroughs on install, config, modules, etc.

      1 Reply Last reply Reply Quote 1
      • J Offline
        joncedimov
        last edited by Feb 12, 2018, 9:45 AM

        Thanks @ninjabreadman, that seems to do the trick for now :)

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          3/3
          Last post
        Enjoying MagicMirror? Please consider a donation!
        MagicMirror created by Michael Teeuw.
        Forum managed by Sam, technical setup by Karsten.
        This forum is using NodeBB as its core | Contributors
        Contact | Privacy Policy