trongate / trongate-framework

The Trongate PHP framework
https://trongate.io
Other
1.12k stars 100 forks source link

Trongate MX !element.hasAttribute(httpMethodAttribute) #207

Open vanHeerwaarden opened 3 weeks ago

vanHeerwaarden commented 3 weeks ago

Hi David, I will complement you with another great future in the trongate framework. After completed the tutorial I was attended the placeholder information is not resetting. So I did a console.log(httpMethodAttribute)

invokeFormPost(element, triggerEvent, httpMethodAttribute, containingForm, event) {
            const { http, formData, targetElement } = Http.commonHttpRequest(element, httpMethodAttribute, containingForm);

            http.onload = function() {
                Dom.attemptHideLoader(containingForm);

                const isSuccessfulResponse = http.status >= 200 && http.status < 300;
                const shouldResetForm = isSuccessfulResponse && element.hasAttribute(httpMethodAttribute);

                if (shouldResetForm) {
                    containingForm.reset();                    
                }
                // containingForm.reset();
                console.log(httpMethodAttribute)

                const responseTarget = element.hasAttribute(httpMethodAttribute) ? **!**element : containingForm;
                Http.handleHttpResponse(http, responseTarget, event);
            };

            try {
                http.send(formData);
            } catch (error) {
                Dom.attemptHideLoader(containingForm);
                console.error('Error sending form request:', error);
            }
        },

console.log(httpMethodAttribute) returns mx-post

So I removed the ! before element : containingForm; now my code behave as I expected. So my question: is this a mistake in the mx code (you can modify) or do I have to check my tutorial code?

image