Is there any better approach than what I am currently doing here:
MVC Controller action creates a select list as:
ProductsDDL.Select(rp => new SelectListItem
{ Value = Model.RawMaterialID.ToString() + "," + plant, Text = Model.FinishedProductName });
And HTML rendered as:
<select id="Products" name="Products">
<option value="3,PLANT1">Finished Product1</option>
<option value="4,PLANT2">Finished Product2</option>
<option value="7,PLANT3">Finished Product3</option>
</select>
On selection change, I use Jquery $.GetJSON to populate another drop down list. The reason I am concatinating PlantID with RawMaterialID is to avoid long query processing time.
On Post to action(string RawIDPlantID), I use Split(',') to get RewMaterialID & PlantID
Other options are to use session to hold PlantID or input hidden field in MVC view.
I typically stay away from using commas as a delimiter in values that represent a single entity, and save the commas delimiting a list of multiple ids. In cases such as yours, I end up using an underscore. Then, should I need to comma separate a list of the IDs, it's easier on the eyes and to parse. But that's completely subjective and up to you, as the developer.
For example
3_PLANT1,4_PLANT2,7_PLANT3
is easier to eyeball
3,PLANT1,4,PLANT2,7,PLANT3
And that was as much criticism as I could muster about your code. The rest of it I'd use, and have used in the past.
Related
I wonder if I can create a query param that take multiple values from dropdown just like a non-typing combobox in the UI of ArangoDB. For example
//A route....
.queryParam('A', joi.any().allow(["true","false,"haha"]).required().default("true"))
The one above produce an dropdow that allow you to choose only 1 value. Is it possible to make them behave like a combo box on arango's UI?
I use this query param join's validation that shows as a drop down in the Arango UI
.queryParam('direction', joi.string().lowercase().valid('inbound', 'outbound', 'any')
.required().description('Direction of traversal from given product (inbound/outbound/any)'
))
My first Post: (be kind )
PROBLEM: I need to extract the View Name from a Text field that contains a full SQL Statements so I can link the field a different data source. There are two text strings that always exist on both sides of the target view. I was hoping to use these as identifying "anchors" along with a substring to bring in the View Name text from between them.
EXAMPLE:
from v_mktg_dm.**VIEWNAME** as lead_sql
(UPPER CASE/BOLD is what I want to extract)
I tried using
SELECT
SUBSTR(SQL_FIELD,INSTR(SQL_FIELD,'FROM V_MKTG_TRM_DM.',19),20) AS PARSED_FIELD
FROM DATABASE.SQL_STORAGE_DATA
But am not getting good results -
Any help is appreciated
You can apply a Regular Expression:
RegExp_Substr_gpl(SQL_FIELD, '(v_mktg_dm\.)(.*?)( AS lead_sql)',1,1,'i',2)
This looks for the string between 'v_mktg_dm.' and ' AS lead_sql'.
RegExp_Substr_gpl is an undocumented variation of RegExp_Substr which simplifies the syntax for ignoring parts of the match
Is it possible to either extract the text portion of a select tag after it is passed to a controller or do something else crafty with rails to get the value between the <option></option> tags?
My raw html is simple:
<select>
<option value></option>
<option value="5">I have a small problem</option>
<option value="10">I have a big problem</option>
<option value="15">I have a massive problem</option
</select>
I'm converting the selected value to integers in my controller which triggers other system calls (such as routing to the correct support person), however, I'd like to be able to also save the text portion into the user's profile for tracking (i.e. `user.issue = "I have a small problem").
Shy of creating some hidden fields and using Javascript, is there another way to get or include the text value when it passes to the controller?
Here is some advice which is going to be very general since you don't give a lot of specifics in your question. Yes, the HTML should be "the same" no matter what but really it does matter how you create it because that reflects how it integrates into the rest of your app.
I would create a table in the DB called severity with rows something like this:
id | text | val
1 | 'small' | 5
2 | 'big' | 10
3 | 'massive' | 15
Now instead of doing translations elsewhere like you imply ("I'm converting the selected value to integers in my controller which triggers other system calls") you can use things like:
problem.severity.text
=> 'massive'
problem.severity.val
=> '15'
Using relationships like has_one, belongs_to, etc. you can then leverage these values or words anywhere in your application. Something as simple as:
<%= f.collection_radio_buttons :user_id, Severity.all, :id, :text %>
I should recommend you to use select2 for multiple values selecting, select2-rails is its integration with rails. It's pretty simple. Give it a shot.
Given a loop like:
#For Each x In item.PostCategory
Dim cats = x.CategoryName & ", "
#Html.ActionLink(cats,
"PostsByCategory", "Posts", New With {.Category = x.CategoryName.ToSeoUrl,
.Page = Nothing}, Nothing)
Next
I need to remove only the last comma and space - everything I have tried removes the commas and spaces in the middle as well as the end. The loop renders categories and I want them separated by a comma and space but do not need or want the trailing comma and space. Each category needs to be a separate link so string.join won't work. I tried trim.substring - that removes the commas in the middle. TrimEnd did not work. I have searched and have not found a solution.
Instead of World, Science, - i want World, Science
You can try to check if x is the last item in PostCategory. If it is true, then append an empty string, else append comma and space :
Dim cats = x.CategoryName & IIf(x.Equals(item.PostCategory.Last()), "", ", ")
There's many different ways to solve this problem. You'll have to determine the best way. Simply, you can just not use a foreach and do a simple for instead. Then you can easily tell if you're on the last item by comparing the index with the count and conditional show or not show the comma based on that.
Alternatively, you can construct a list of the string values this code would otherwise render directly to the page and then use string.Join to join the list items separated by ", ". string.Join never appends the delimiter to the end, so that fixes your problem.
You could also go fancier with some sort of editor template or partial view or even create a HtmlHelper extension. If just depends on how you want to handle it.
I am retrieving a few bunches of int/string pairs that I want to generate dropdown lists for, and subsequently use these filter a collection of items.
Currently, I create these filters as SelectLists in the Controller this way:
foreach (int key in filterChoices.Keys)
subFilter.Add(new SelectListItem {Value = key.ToString(), Text = filterChoices[key]});
where "filterChoices" holds the id (int) and text (string) as key, value pairs.
Then I'm a bit confused as to what to do. I have tried to put together bits and pieces from various examples, but don't really understand what's going on.
This is what I'm trying currently:
Html.DropDownListFor(m => m.SelectedDimension, new SelectList(Model.DimensionFilter, "Text", "Value", Model.DimensionFilter.First().Text));
The first part, I'm not really sure what its use is, but I am assuming it's the property whose change controls what is being selected in the list? Something along those lines? So I'm trying to set this int to some arbitrary value that corresponds to one filter entry, but to no avail.
No DropDown shows up.
just use
#Html.DropDownListFor(m => m.SelectedDimension, Model.DimensionFilter)
if you already created a selectList