I have set error msg for form validation.. but trying to figure out how to remove error msg | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

I have set error msg for form validation.. but trying to figure out how to remove error msg

Please help me to progress in this tiny app😎 https://code.sololearn.com/WK0XU6f0mp1x/?ref=app

13th Apr 2020, 11:28 AM
BangArray
BangArray - avatar
10 Réponses
0
Nice design :) You may be aware that in code playground you need to wait for document load ends before accessing DOM as it seems you've tried to wrap initialisation part in an onload event handler... but... The functions defined outside this main handler, doesn't have access to this function scope, and the reference you've defined at start (const title, author, isbn; outside the init function, in global scope) are still initialized with 'undefined' or 'null', as they are assigned before DOM was ready (and targeted elements accessible). A better and cleanest way would been to wrap your whole code in the main handler (no polute global scope, and private global-like scope -- kind of anonymous namespace), but now that's quickest to fix as is: Replace global const init by just var declaration: var title, author, isbn; ... and delete 'const' from these 3 variables initialisation in the init function (no 'var', no 'let': you want to assign the global vars for being accessibke from outside). That's all folks !
14th Apr 2020, 4:24 AM
visph
visph - avatar
0
have set error msg for form validation.. but trying to figure out how to remove error msg
14th Apr 2020, 7:53 AM
BangArray
BangArray - avatar
0
I told you at end of my first post after explanation of how and why: now that's quickest to fix as is: Replace global const init by just var declaration: var title, author, isbn; ... and delete 'const' from these 3 variables initialisation in the init function (no 'var', no 'let': you want to assign the global vars for being accessible from outside).
14th Apr 2020, 7:59 AM
visph
visph - avatar
0
Thanks for explanations 🙏 I fixed that what you said.. But i am sorry mate my question is different.. I have made function to display error msg if you don't fill input fields and try to add book .. Please try to run my app again..
14th Apr 2020, 8:03 AM
BangArray
BangArray - avatar
0
I don't understand your problem: if you follow completly my advices, your code will work fine, form validation included... (even if your last saved version is not working at all (blank page) if you run it in this intermediate state (you only follow the first part of the 2 things to do -- don't forget the last paragraph ^^)
14th Apr 2020, 8:23 AM
visph
visph - avatar
14th Apr 2020, 8:26 AM
BangArray
BangArray - avatar
0
Please try to run app now.. press "ADD BOOK" button without filling any inputs.. it will display error msg ("title mus be filled, author must be filled, isbn must be filled " under respective input fields...
14th Apr 2020, 8:31 AM
BangArray
BangArray - avatar
0
Well, that's now working, isn't it? ... Even if time of loading is quite long ;P But I have found the accountable: remove the font-awesome js script, and you'll got an instant loading :)
14th Apr 2020, 8:32 AM
visph
visph - avatar
0
... and error msg are displayed as they must ^^
14th Apr 2020, 8:34 AM
visph
visph - avatar
0
Yeah thanks.. trying to make a function that removes error msg displayed on screen
14th Apr 2020, 8:34 AM
BangArray
BangArray - avatar