/src/wt/src/Wt/WRadioButton.C
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2008 Emweb bv, Herent, Belgium. |
3 | | * |
4 | | * See the LICENSE file for terms of use. |
5 | | */ |
6 | | |
7 | | #include "Wt/WRadioButton.h" |
8 | | #include "Wt/WButtonGroup.h" |
9 | | |
10 | | #include "WebUtils.h" |
11 | | #include "DomElement.h" |
12 | | |
13 | | namespace Wt { |
14 | | |
15 | | WRadioButton::WRadioButton() |
16 | 0 | : buttonGroup_(nullptr) |
17 | 0 | { |
18 | 0 | setFormObject(true); |
19 | 0 | } |
20 | | |
21 | | WRadioButton::WRadioButton(const WString& text) |
22 | 0 | : WAbstractToggleButton(text), |
23 | 0 | buttonGroup_(nullptr) |
24 | 0 | { |
25 | 0 | setFormObject(true); |
26 | 0 | } |
27 | | |
28 | | WRadioButton::~WRadioButton() |
29 | 0 | { |
30 | 0 | if (buttonGroup_) |
31 | 0 | buttonGroup_->removeButton(this); |
32 | 0 | } |
33 | | |
34 | | void WRadioButton::updateInput(DomElement& input, bool all) |
35 | 0 | { |
36 | 0 | if (all) { |
37 | 0 | input.setAttribute("type", "radio"); |
38 | |
|
39 | 0 | if (buttonGroup_) { |
40 | 0 | input.setAttribute("name", buttonGroup_->id()); |
41 | 0 | input.setAttribute("value", id()); |
42 | 0 | } |
43 | 0 | } |
44 | 0 | } |
45 | | |
46 | | void WRadioButton::getFormObjects(FormObjectsMap& formObjects) |
47 | 0 | { |
48 | 0 | if (buttonGroup_) |
49 | 0 | formObjects[buttonGroup_->id()] = buttonGroup_.get(); |
50 | |
|
51 | 0 | WAbstractToggleButton::getFormObjects(formObjects); |
52 | 0 | } |
53 | | |
54 | | void WRadioButton::setGroup(std::shared_ptr<WButtonGroup> group) |
55 | 0 | { |
56 | 0 | buttonGroup_ = group; |
57 | 0 | formDataChanged(); |
58 | 0 | } |
59 | | |
60 | | void WRadioButton::setFormData(const FormData& formData) |
61 | 0 | { |
62 | 0 | if (flags_.test(BIT_STATE_CHANGED) || isReadOnly()) |
63 | 0 | return; |
64 | | |
65 | 0 | if (buttonGroup_) { |
66 | 0 | if (!Utils::isEmpty(formData.values) && formData.values[0] == "1") { |
67 | 0 | buttonGroup_->uncheckOthers(this); |
68 | 0 | state_ = CheckState::Checked; |
69 | 0 | } |
70 | 0 | } else { |
71 | 0 | WAbstractToggleButton::setFormData(formData); |
72 | 0 | } |
73 | 0 | } |
74 | | |
75 | | } |