Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Library/Source/Controls/CheckBoxControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

using System;
using System.Collections.Generic;
using System.Web;

namespace Vici.Mvc
{
Expand All @@ -45,13 +46,14 @@ protected override string GenerateHtml(View view, string className, string class
string s = "<input type=\"checkbox\"";

if (!string.IsNullOrEmpty(Value))
s += " value=\"" + Value + "\"";
s += " value=\"" + HttpUtility.HtmlEncode(Value) + "\"";

s = AddIdAttribute(s);
s = AddNameAttribute(s);
s = AddClassAttribute(s, className, classNameError);
s = AddEnabledAttribute(s);
s = AddOnChangeAttribute(s);
s = AddTabIndexAttribute(s);

if (!string.IsNullOrEmpty(OnClick))
s += " onclick=\"" + OnClick + "\"";
Expand Down
3 changes: 2 additions & 1 deletion Library/Source/Controls/CheckBoxListControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,11 @@ protected override string GenerateHtml(View view, string className, string class
s = AddNameAttribute(s);
s = AddEnabledAttribute(s);
s = AddOnChangeAttribute(s);
s = AddTabIndexAttribute(s);

string value = view.ParseTranslations(Items[i].Value.ToString());

s += " type='checkbox' value='" + Items[i].Key + "'" + (isChecked ? " checked='checked'" : "") + " />" + HttpUtility.HtmlEncode(value);
s += " type='checkbox' value='" + HttpUtility.HtmlEncode(Items[i].Key.ToString()) + "'" + (isChecked ? " checked='checked'" : "") + " />" + HttpUtility.HtmlEncode(value);

if (Style == CheckBoxListStyle.Div)
s += "</div>";
Expand Down
15 changes: 15 additions & 0 deletions Library/Source/Controls/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public abstract class Control
private string _cssClassError;
private bool _autoPost;
private string _onChange;
private short _tabIndex = -1;
private bool _enabled = true;

private static readonly Dictionary<Type, string> _defaultCssClasses = new Dictionary<Type, string>();
Expand Down Expand Up @@ -157,6 +158,12 @@ public string OnChange
set { _onChange = value; }
}

public short TabIndex
{
get { return _tabIndex; }
set { _tabIndex = value; }
}

public bool Enabled
{
get { return _enabled; }
Expand Down Expand Up @@ -273,6 +280,14 @@ protected string AddEnabledAttribute(string html)
return html;
}

protected string AddTabIndexAttribute(string html)
{
if (TabIndex >= 0)
html += " tabindex=\""+ TabIndex + "\"";

return html;
}


public void HandlePostBack()
{
Expand Down
3 changes: 2 additions & 1 deletion Library/Source/Controls/DropdownControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ protected override string GenerateHtml(View view, string className, string class
s = AddClassAttribute(s, className , classNameError);
s = AddEnabledAttribute(s);
s = AddOnChangeAttribute(s);
s = AddTabIndexAttribute(s);

s += ">\r\n";

Expand All @@ -267,7 +268,7 @@ protected override string GenerateHtml(View view, string className, string class

string value = view.ParseTranslations(String.Format(formatString, Items[i].Key, Items[i].Value));

s += "<option value='" + Items[i].Key + "'" + (isCurrent ? " selected='selected'" : "") + ">" + HttpUtility.HtmlEncode(value) + "</option>\r\n";
s += "<option value='" + HttpUtility.HtmlEncode(Items[i].Key.ToString()) + "'" + (isCurrent ? " selected='selected'" : "") + ">" + HttpUtility.HtmlEncode(value) + "</option>\r\n";
}

s += "</select>";
Expand Down
1 change: 1 addition & 0 deletions Library/Source/Controls/MemoControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ protected override string GenerateHtml(View view, string className, string clasE
s = AddEnabledAttribute(s);
s = AddOnChangeAttribute(s);
s = AddReadOnlyAttribute(s);
s = AddTabIndexAttribute(s);

s += " rows=\"" + Height + "\"";
s += " cols=\"" + Width + "\"";
Expand Down
1 change: 1 addition & 0 deletions Library/Source/Controls/PasswordBoxControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected override string GenerateHtml(View view, string className, string clasE
s = AddClassAttribute(s, className, clasError);
s = AddEnabledAttribute(s);
s = AddOnChangeAttribute(s);
s = AddTabIndexAttribute(s);

if (MaxLength != Int32.MaxValue)
s += " maxlength=\"" + MaxLength + "\"";
Expand Down
1 change: 1 addition & 0 deletions Library/Source/Controls/RadioButtonControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ protected override string GenerateHtml(View view, string className, string class

s = AddClassAttribute(s, className, classNameError);
s = AddEnabledAttribute(s);
s = AddTabIndexAttribute(s);

if (!string.IsNullOrEmpty(_onClick))
s += " onclick=\"" + _onClick + "\"";
Expand Down
19 changes: 14 additions & 5 deletions Library/Source/Controls/RadioButtonListControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public Item(object key, object value)
private string _keyMember;
private string _valueMember;

private bool _useLineBreaks;

private string _valueFormatString;

private readonly List<Item> _items = new List<Item>();
Expand Down Expand Up @@ -126,6 +128,12 @@ public string ValueMember
}
}

public bool UseLineBreaks
{
get { return _useLineBreaks; }
set { _useLineBreaks = value; }
}

public string ValueFormatString
{
get { return _valueFormatString; }
Expand Down Expand Up @@ -183,15 +191,16 @@ protected override string GenerateHtml(View view, string className, string class
string formatString = _valueFormatString ?? "{1}";

// Append the elements of the list
for (int i = 0; i < Items.Count; i++)
foreach (Item t in Items)
{
bool isCurrent = Equals(Value, Items[i].Key);
bool isCurrent = Equals(Value, t.Key);

string value = view.ParseTranslations(String.Format(formatString, Items[i].Key, Items[i].Value));
string value = view.ParseTranslations(String.Format(formatString, t.Key, t.Value));

output.Append("<input type=\"radio\" " + AddOnChangeAttribute("") + " " +
AddClassAttribute("", className, classNameError) + " " + AddNameAttribute("") + " value='" +
Items[i].Key + "'" + (isCurrent ? " checked" : "") + ">" + HttpUtility.HtmlEncode(value) + "\r\n");
AddClassAttribute("", className, classNameError) + " " + AddNameAttribute("") + " value=\"" +
HttpUtility.HtmlEncode(t.Key.ToString()) + "\"" + (isCurrent ? " checked" : "") + ">" + HttpUtility.HtmlEncode(value) +
(_useLineBreaks ? "<br />" : "") + "\r\n");
}

return output.ToString();
Expand Down
11 changes: 11 additions & 0 deletions Library/Source/Controls/TextBoxControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class TextBoxControl : Control
private string _onKeyDown;
private string _onKeyUp;
private bool _readOnly;
private string _placeholder;

public TextBoxControl(string name) : base(name)
{
Expand Down Expand Up @@ -92,6 +93,12 @@ public bool ReadOnly
set { _readOnly = value; }
}

public string Placeholder
{
get { return _placeholder; }
set { _placeholder = value; }
}

protected override string GenerateHtml(View view, string className, string clasError)
{
string s = "<input type=\"text\" value=\"" + HttpUtility.HtmlEncode(_value) + "\"";
Expand All @@ -102,6 +109,7 @@ protected override string GenerateHtml(View view, string className, string clasE
s = AddEnabledAttribute(s);
s = AddOnChangeAttribute(s);
s = AddReadOnlyAttribute(s);
s = AddTabIndexAttribute(s);

if (Size != 0)
s += " size=\"" + Size + "\"";
Expand All @@ -121,6 +129,9 @@ protected override string GenerateHtml(View view, string className, string clasE
if (!string.IsNullOrEmpty(OnKeyPress))
s += " onkeypress=\"" + OnKeyPress + "\"";

if (!string.IsNullOrEmpty(Placeholder))
s += " placeholder=\"" + HttpUtility.HtmlEncode(Placeholder) + "\"";

return s + "/>";
}

Expand Down
5 changes: 3 additions & 2 deletions Library/Source/FormAttributes/FormCheckBoxListAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ protected internal override void SetControlValue(Control control, object value)
else
checkBoxListControl.Values.Clear();

foreach (object valueObject in (IEnumerable) value)
checkBoxListControl.Values.Add(valueObject);
if (value != null)
foreach (object valueObject in (IEnumerable) value)
checkBoxListControl.Values.Add(valueObject);
}

protected internal override Control CreateControl(string name)
Expand Down
2 changes: 2 additions & 0 deletions Library/Source/FormAttributes/FormFieldAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class FormFieldAttribute : Attribute
public bool AutoPost;
public string OnChange;
public string ValidationErrorMsg;
public short TabIndex;

protected internal Type FieldType;
internal object FormData;
Expand All @@ -53,6 +54,7 @@ internal Control CreateControl()
control.Id = Id;
control.AutoPost = AutoPost;
control.OnChange = OnChange;
control.TabIndex = TabIndex;

return control;
}
Expand Down
2 changes: 2 additions & 0 deletions Library/Source/FormAttributes/FormRadioButtonListAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class FormRadioButtonListAttribute : FormFieldAttribute
public string KeyMember { get; set; }
public string ValueMember { get; set; }
public object DataSource { get; set; }
public bool UseLineBreaks { get; set; }
public string ValueFormatString { get; set; }

public FormRadioButtonListAttribute()
Expand Down Expand Up @@ -61,6 +62,7 @@ protected internal override Control CreateControl(string name)
DataSource = DataSource,
KeyMember = KeyMember,
ValueMember = ValueMember,
UseLineBreaks = UseLineBreaks,
ValueFormatString = ValueFormatString
};

Expand Down
2 changes: 2 additions & 0 deletions Library/Source/FormAttributes/FormTextBoxAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class FormTextBoxAttribute : FormFieldAttribute
public string OnKeyUp;
public string OnKeyPress;
public bool ReadOnly;
public string Placeholder;

protected internal override bool IsRightType()
{
Expand Down Expand Up @@ -87,6 +88,7 @@ protected internal override Control CreateControl(string name)
control.OnKeyUp = OnKeyUp;
control.OnKeyPress = OnKeyPress;
control.ReadOnly = ReadOnly;
control.Placeholder = Placeholder;

return control;
}
Expand Down