![]() |
jQuery and Mysidia: A struggle
I know well that mysidia is anti-javascript currently, specially ajax, due to the way the pages are rendered. However, I started this and I really want to find a way.
So in my little test site for 1.3.4, I've been trying to use ajax to check if the username and e-mail already exists and tell the user real-time. I've accomplished this somewhat, but I came across two problems: 1) The function I'm using to verify the variables sent by the ajax request (for example, username and email) became a page itself (since most .php files and their respective functions are converted to html), like so http://website.com/register/checkusernamefunction. lol To avoid this (access from users to pages that shouldn't be pages), I throw an error if the variable through post is empty (if username has no value). Which is kind of not a good way to do it... Is there a way to correct this? Maybe stop the page from rendering automatically? 2) I'm doing the verification of the word I write in the input field for each key press PHP Code:
I tried using keydown and it stays behind one character for some reason (if I write "SampleAccount2" it will assume I wrote "SampleAccount", which is not as random as keypress or keyup). Instead of each key press, I thought to use it with each click on the field, but it's kinda impractical for the users, since they have to click to write the username and then click outside the input field and then click the input again to check if it's being used. I'm quite a newbie at this jquery thing, so I'm asking if these are the best ways to do it or if there are alternatives. Also another thing. My question is: is it bad practice to have the script functions displayed on the page directly instead of having them all in a single file .js? I'm echoing the javascript I need in each page since including the file didn't seem to work |
I've had my thoughts on a verification system for a while, too, but the way pages are rendered definitely does step in the way. I've made an ajax verification system before, not for Mysidia, of course, so I may attempt to hack it in somehow. I'll be sure and post the results someplace.
(Whether or not it's bad practice to or not to have a separate file comes down to a variety of things. I'd think of it like css. Sometimes you may need to do a little inline styling and that's fine, especially if it's only ever going to be used on that one thing. I'd say it's definitely useless to include anything on every single page if its not actively being used on it, but again, the way pages are rendered right now makes that hard. You could probably echo in a <script> only where it's used, but depending on what it is, you may need to creatively queue the script to only run after the page, and jQuery, has loaded.) As for what you're doing here and now with the keyup and such... I'd personally recommend only checking the database once the input box as lost focus and they've tabbed or clicked away...? I think that's how I did it...? Good luck, though. I'll try my hand at it, but probably in a week or two. I've got some other commitments right now. |
Thank you! When you get to it it will be lovely if you can share the results ^^ I will share mine if I can put it to work and fix these annoyances. Or maybe I can post what I already have and maybe we can fix it somehow when you have time?
I tried the onblur() thing, but it didn't seem to do anything xD I will investigate on how to use it. Makes sense to only avaliate the full word after clicking away or tabbing (and thank you, I agree on that xD I will keep echo'ing then, I don't know how much javascript I will need - I will probably only have that stuff in the register page plus in another page, so there's really no need to include it everywhere I guess) --------------------------------------------------------- So with tabbing, it seems to work perfectly. With anything else like clicking outside it keeps spazzing out: Without me doing anything it will keep reading the full word, then half the word, then just one letter lol xD The current code is like this: PHP Code:
|
Ok, well, on my test (unrelated to Mysidia):
Code:
<script> Code:
<? You can safely ignore all the adding and removing of success/valid/error classes I did (because I was combining it with another system that also checked for minimum/maximum length requirements... and that passwords had a number, matched, and emails had an @). I was using the same span for both types of confirmation of success and if one was true but not the other, the whole span needed to be red. (ie: Yeah, it fits the minimum requirements for length, but it's taken so it needs to be red and throw and error, not have the green success check.) |
Well seems that a lot of you are struggling with javascript in Mysidia, particulally AJAX. I will try to make the GUI system better at handling javascript in Mys v1.4.0 so you can add javascript events like onclick, onkeypress easily. Not sure how much this will help though, but at least its some kind of improvements I can offer.
|
Quote:
Aah thanks for sharing! I will try to use all the .focus and .change functions to see if it corrects the spazzing that happens sometimes There's a few issues with mysidia's pages, so I kinda went around the problems lol For example the php spits out errors in the result of the ajax request if the document isn't created and doesn't have a title, so you have to create it as a page. Because my function turns into a page itself, that means users can access it, so I made it throw exceptions if the the value recieved is null. Then if the function is fine, the result spits out the full page's html xD I went around this by accessing the characters of the result (since it ends up being a string). So if the php echos 0 as result, the result will be a string with 0 followed by the predefined html of the page. So result[0] is the first element of that string and the result I actually want (that's why I compare result[0] and not result) It's a very... sloppy way of going around it. And maybe it's what causes the spazzing by making it slow down, no idea xD I will try again with other ways soon enough x.x Anyway, I added this function to register.php page: (hopefully it's useful) PHP Code:
Quote:
---- OOOH I was checking the focus thing after a key press, I think that's why it spazzed! The code is now (I made it a function since I will use it for email as well): PHP Code:
|
Nice! Will you go forth and make an official mod thread for this? I think it's a rather in-demand feature.
|
Yeah, I think! I was finishing the verifications of the stuff I wanted in the registration page before putting it up - I think it's done (can be tested in the same link)
-> Verifies Username and password size -> Verifies Username, e-mail and date format -> Verifiies existence of Username and e-mail in database I will still clean it up somewhat tomorrow and then write a mini guide for it. Not sure if this should be a mod or just a tutorial? The problem with the php spitting the full html as response plus turning the php into a page itself automatially still stands - I've avoided these problems, not solved them, which is kinda sucky xDD |
In trying to do this myself, I've run across a lot of problems. How're your register and registerview pages set up now, in full?
Also, for the fun of it, this may interest you: Code:
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.11.1/jquery.validate.min.js"></script> |
That looks interesting yes, quite nice o.o I will try to incorporate it somehow xD
What errors are you getting? I had troubles when I accidentely closed the Comment field, so the script wouldn't even run and I didn't understand why lol If there's a little small error somewhere in the javascript, no script will run. For example I was trying to use <font color> and since it was deprecated it made the script not run at all register.php: PHP Code:
PHP Code:
|
All times are GMT -5. The time now is 11:04 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.