FMCrash when calling setInputMask
Added by Filipe Marques 14 days ago
In WLineEdit::setText the if statement is missing "&& javaScriptDefined_".
And because of that I encountered a situation where the Wt crashes with this JS error:
Wt4_14_2.$('o1hpzoxn').wtLObj.setValue('3510-010'); <-- referencing the wtObj before "new Wt4_14_2.WLineEdit"
Wt4_14_2.setValidationState(Wt4_14_2.$('o1hpzoxn'),true,'',1);
new Wt4_14_2.WLineEdit(Wt,Wt4_14_2.$('o1hpzoxn'),'9999_999','-','3510-010','!!!!!!!!','',0x0);
TypeError: Cannot read properties of undefined (reading 'setValue')
void WLineEdit::setText(const WT_USTRING& text)
{
...
if (isRendered() && javaScriptDefined_ && !inputMask_.empty()) { <-- Fix
doJavaScript(jsRef() + ".wtLObj"
".setValue(" + WWebWidget::jsStringLiteral(newDisplayText) + ");");
}
...
}
Replies (3)
RM RE: Crash when calling setInputMask - Added by Romain Mardulyn 13 days ago
Hi Filipe,
Could you describe how you encounter that crash? If you can make small example reproducing the JS error would be ideal, but if you cannot do that, I will need more information so that I can make one myself.
FM RE: Crash when calling setInputMask - Added by Filipe Marques 13 days ago
#include <QCoreApplication>
#include <Wt/Http/Client.h>
#include <Wt/WApplication.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
#include <Wt/WServer.h>
class Application : public Wt::WApplication
{
public:
Application(const Wt::WEnvironment& environment) : Wt::WApplication(environment)
{
enableUpdates(true);
m_client = addChild(std::make_unique<Wt::Http::Client>());
m_client->done().connect([this] {
Wt::WApplication::UpdateLock lock(Wt::WApplication::instance());
if (lock)
{
m_lineEdit->setInputMask("9999-999;_"); // Inverter as linhas eu não crasha
m_lineEdit->setText("3510-010");
Wt::WApplication::instance()->triggerUpdate();
}
});
// root()->addNew<Wt::WPushButton>("Click")->clicked().connect([this] {
m_lineEdit = root()->addWidget(std::make_unique<Wt::WLineEdit>());
m_client->get("https://dummy.restapiexample.com/api/v1/employee/1");
// });
}
Wt::WLineEdit *m_lineEdit;
Wt::Http::Client* m_client;
};
std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment& env)
{
return std::make_unique<Application>(env);
}
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
try
{
Wt::WServer server(argc, argv, WTHTTP_CONFIGURATION);
server.addEntryPoint(Wt::EntryPointType::Application, createApplication);
server.run();
}
catch (std::exception& e)
{
std::cerr << "exception: " << e.what() << std::endl;
}
}
RM RE: Crash when calling setInputMask - Added by Romain Mardulyn 13 days ago
Thank you for your help.
I created a Issue #14789 to track the bug.