Sep 29, 2014, 7:49 AM
[CLOSED] Populate TagField From Multiselect and Remove Item from Multiselect
I have 2 MultiSelect and a TagField,I am tring to add item in tag field on select MultiSelect item as well as remove the item from MultiSelect which is add to TagField.
here I face some difficulty on selecting items from Multiselect.
1.Click on "Basic" from "List 1" and then click on "+" from "List 2"
the "+" not added to TagField.and add items in TagField is very uncertain.add item in TagField not happen simultaneously.
2.Also I try to remove item from "List 1" after adding to TagFiled.I am getting a javascript error,don't understand why?that's why I comment out this line.
View
here I face some difficulty on selecting items from Multiselect.
1.Click on "Basic" from "List 1" and then click on "+" from "List 2"
the "+" not added to TagField.and add items in TagField is very uncertain.add item in TagField not happen simultaneously.
2.Also I try to remove item from "List 1" after adding to TagFiled.I am getting a javascript error,don't understand why?that's why I comment out this line.
TypeError: this.getSubmitArray(...)[0] is undefined
bellow is my sample code,plz helpView
@{
Layout = null;
var X = Html.X();
}
<script>
var populateTag = function (value,text) {
App.tag.addItem(text, value)
App.tag.addTag(value)
}
</script>
@X.ResourceManager()
@( X.Panel().Layout(LayoutType.VBox).Items
(
X.FieldContainer()
.Layout(LayoutType.Table)
.LayoutConfig(new TableLayoutConfig() { Columns = 2 })
.Items(
X.Label().Html("<div class='label'>List 1</div>"),
X.Label().Html("<div class='label'>List 2</div>"),
X.MultiSelect()
.Height(260)
.ID("MS1")
.Width(300)
.Border(true)
.DisplayField("opText")
.ValueField("opValue")
.MaxSelections(1)
.SingleSelect(true)
.Listeners(l =>
{
l.Change.Handler = @"populateTag(this.getSubmitArray()[0]['value'],this.getSubmitArray()[0]['text'])
";
})
.Store(X.Store()
.ID("Store1")
.Data(ViewBag.op)
.Model(X.Model()
.IDProperty("opValue")
.Fields(
Html.X().ModelField().Name("opValue").Mapping("opValue").Type(ModelFieldType.Int),
Html.X().ModelField().Name("opText").Mapping("opText").Type(ModelFieldType.String)
)
)
),
X.MultiSelect()
.ID("MS2")
.Width(300)
.Height(260)
.SingleSelect(true)
.DisplayField("componentText")
.ValueField("componentValue")
.Listeners(l =>
{
l.Change.Handler = @"populateTag(this.getSubmitArray()[0]['value'],this.getSubmitArray()[0]['text'])
// this.getStore().removeAt(this.getSubmitArray()[0]['index'])
";
})
.Store(X.Store()
.ID("Store2")
.Data(ViewBag.Component)
.Model(X.Model()
.IDProperty("componentValue")
.Fields(
Html.X().ModelField().Name("componentValue").Mapping("componentValue").Type(ModelFieldType.Int),
Html.X().ModelField().Name("componentText").Mapping("componentText").Type(ModelFieldType.String)
)
)
)
)
,
X.TagField()
.ID("tag")
.HideSelected(true)
.Width(800)
.HideTrigger(true)
.Editable(true)
.DisplayField("tagtext")
.ValueField("tagvalue")
.MultiSelect(true)
.Store(X.Store()
.ID("Store3")
.Model(X.Model()
.Fields(
Html.X().ModelField().Name("tagvalue").Mapping("tagvalue").Type(ModelFieldType.Int),
Html.X().ModelField().Name("tagtext").Mapping("tagtext").Type(ModelFieldType.String)
)
)
)
)
)
Controllerpublic class formulaController : Controller
{
//
// GET: /formula/
public ActionResult Index()
{
ViewBag.op = Getoperator();
ViewBag.Component = GetComponent();
return View();
}
public List<OP> Getoperator()
{
List<OP> _op = new List<OP>();
_op.Add(new OP
{
opValue=1,
opText="+",
});
_op.Add(new OP
{
opValue = 2,
opText = "-",
});
_op.Add(new OP
{
opValue = 3,
opText = "*",
});
_op.Add(new OP
{
opValue = 4,
opText = "/",
});
_op.Add(new OP
{
opValue = 4,
opText = "%",
});
return _op;
}
public List<Component> GetComponent()
{
List<Component> _Component = new List<Component>();
_Component.Add(new Component
{
componentValue = 1,
componentText = "Basic",
});
_Component.Add(new Component
{
componentValue = 2,
componentText = "HRA",
});
_Component.Add(new Component
{
componentValue = 3,
componentText = "PF",
});
_Component.Add(new Component
{
componentValue = 4,
componentText = "ESI",
});
return _Component;
}
}
public class OP
{
public int opValue { get; set; }
public string opText { get; set; }
}
public class Component
{
public int componentValue { get; set; }
public string componentText { get; set; }
}
Last edited by Daniil; Oct 03, 2014 at 1:42 PM.
Reason: [CLOSED]