Hello,
Setting focus is impossible without JavaScript, in pure HTML version.
So, any Wt solution would work only if JavaScript is enabled.
You can iterate all widgets in Wt and apply Wt code I proposed.
WWebWidget and WObject have children() method, which can be used to
get all children. I am not sure if this works for WCompositeWidget.
Method findFormWidgets adds all form widgets to vector form_widgets_,
method enterAsTab connects enterPressed() signal of each widget from
form_widgets_ to setFocus() slot of next widget. Last widget is
connected to first widget.
#include <boost/foreach.hpp>
#include <Wt/WApplication>
#include <Wt/WLineEdit>
#include <Wt/WContainerWidget>
using namespace Wt;
class App : public WApplication {
public:
App(const WEnvironment& env):
WApplication(env) {
WLineEdit* le_1 = new WLineEdit(root());
WLineEdit* le_2 = new WLineEdit(root());
findFormWidgets(root());
enterAsTab();
}
std::vector<WFormWidget*> form_widgets_;
void findFormWidgets(WObject* widget) {
WFormWidget* form_widget = dynamic_cast<WFormWidget*>(widget);
if (form_widget) {
form_widgets_.push_back(form_widget);
}
BOOST_FOREACH (WObject* child, widget->children()) {
findFormWidgets(child);
}
WWebWidget* web_widget = dynamic_cast<WWebWidget*>(widget);
if (web_widget) {
BOOST_FOREACH (WWidget* child, web_widget->children()) {
findFormWidgets(child);
}
}
}
void enterAsTab() {
if (form_widgets_.size() >= 2) {
for (int i = 1; i < form_widgets_.size(); i++) {
WFormWidget* next = form_widgets_[i];
WFormWidget* prev = form_widgets_[i - 1];
prev->enterPressed().connect(next,
&WFormWidget::setFocus);
}
form_widgets_.back()->enterPressed()
.connect(form_widgets_.front(), &WFormWidget::setFocus);
}
}
};
WApplication* createApp(const WEnvironment& env) {
return new App(env);
}
int main(int argc, char** argv) {
return WRun(argc, argv, &createApp);
}
Regards,
Boris Nagaev
On Sat, Nov 23, 2013 at 7:14 AM, Muhammad Nasser Al-Noimi
<[email protected]> wrote:
> Hi,
>
> I did what I want using Javascript, But I wished if I could do it using
> Wt. I called the following method at appliction start
>
> this->addAutoJavaScript(
> "$('input[type=text]').keydown(function(e){ "
> "var next_idx = $('input[type=text]').index(this) +
> 1; "
> "var tot_idx =
> $('body').find('input[type=text]').length; "
> "if(e.keyCode == 13){ "
> "if(tot_idx == next_idx) "
> "$('input[type=text]:eq(0)').focus(); "
> " else "
> "$('input[type=text]:eq(' + next_idx +
> ')').focus(); "
> "} "
> "}); ");
>
> Reference:
> http://snipplr.com/view/53099/
>
> Thanks,
> Nasser
>
> On 22 نوف, 2013 ص 02:38, Muhammad Nasser Al-Noimi wrote:
>> Thanks you for reply, I did this but it is not effective way I want
> > something more general.
> >
> > On 22 نوف, 2013 ص 01:18, Nagaev Boris wrote:
> >> Hello!
> >>
> >> You can connect each widget's enterPressed to setFocus of next
> >> widget manually.
> >>
> >> #include <Wt/WApplication> #include <Wt/WLineEdit> #include
> >> <Wt/WContainerWidget>
> >>
> >> using namespace Wt;
> >>
> >> class App : public WApplication { public: App(const WEnvironment&
> >> env): WApplication(env) { WLineEdit* le_1 = new WLineEdit(root());
> >> WLineEdit* le_2 = new WLineEdit(root());
> >> le_1->enterPressed().connect(le_2, &WFormWidget::setFocus); } };
> >>
> >> WApplication* createApp(const WEnvironment& env) { return new
> >> App(env); }
> >>
> >> int main(int argc, char** argv) { return WRun(argc, argv,
> >> &createApp); }
> >>
> >> Regards, Boris Nagaev
> >>
> >> On Fri, Nov 22, 2013 at 2:57 AM, Muhammad Nasser Al-Noimi
> >> <[email protected]> wrote:
> >>> Hi,
> >>>
> >>> Is there any way to set Enter Key as Tab to Move Focus to next
> >>> Control? I tried to use globalEnterPressedbut I couldn't get next
> >>> control to make it focus.
> >>>
> >>> Thanks, Nasser
> >>>
> >>>
> ------------------------------------------------------------------------------
> >>>
> >>>
> Shape the Mobile Experience: Free Subscription
>>>> Software experts and developers: Be at the forefront of tech
> >>> innovation. Intel(R) Software Adrenaline delivers strategic
> >>> insight and game-changing conversations that shape the rapidly
> >>> evolving mobile landscape. Sign up now.
> >>>
> http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
> >>>
> >>>
> _______________________________________________
>>>> witty-interest mailing list [email protected]
> >>> https://lists.sourceforge.net/lists/listinfo/witty-interest
> >>
> ------------------------------------------------------------------------------
> >>
> >>
> Shape the Mobile Experience: Free Subscription
>>> Software experts and developers: Be at the forefront of tech
> >> innovation. Intel(R) Software Adrenaline delivers strategic insight
> >> and game-changing conversations that shape the rapidly evolving
> >> mobile landscape. Sign up now.
> >>
> http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
> >>
> >>
> _______________________________________________
>>> witty-interest mailing list [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/witty-interest
> >>
> >
>
>
>
> ------------------------------------------------------------------------------
> Shape the Mobile Experience: Free Subscription
> Software experts and developers: Be at the forefront of tech innovation.
> Intel(R) Software Adrenaline delivers strategic insight and game-changing
> conversations that shape the rapidly evolving mobile landscape. Sign up now.
> http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
> _______________________________________________
> witty-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/witty-interest
------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing
conversations that shape the rapidly evolving mobile landscape. Sign up now.
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest