Pass variable to Simple_Form custom input - ruby-on-rails-3

I'm trying to record multiple records using a simple_form custom input. My input is:
class InlinedateInput < SimpleForm::Inputs::Base
def input
"#{#builder.text_field("startmonth", input_html_options)}".html_safe + "/" + "#
{#builder.text_field("startday", input_html_options)}".html_safe + "/" "#
{#builder.text_field("startyear", input_html_options)}".html_safe + "To: " "#
{#builder.text_field("endmonth", input_html_options)}".html_safe + "/" + "#
{#builder.text_field("endday", input_html_options)}".html_safe + "/" "#
{#builder.text_field("endyear", input_html_options)}".html_safe + "Price:" "#
{#builder.text_field("price", input_html_options)}".html_safe
end
#Makes the label target the day input
def label_target
"month"
end
end
Basically, the problem is that I have a bunch of different inputs defined in this input. So if I try to use this method a few times in a form it will only submit the last one. I need someway to pass a counter variable from my form so that I can have startday_1, startday_2, etc. Any ideas?

You can pass any parameter you want to your custom input through options hash.
For example, you can easily pass custom parameter (counter) to your input:
= f.input :my_field, :as => :custom_input, :counter => 2
and access it into your custom input code:
class CustomInput < SimpleForm::Inputs::StringInput
def input
counter = options[:counter] || -1
input_html_options[:value] = counter
super
end
end

Related

Getting "list assignment out of range" error when setting variable through exec or locals()

I am trying to change a variable by referring to it via a string.
The problem arises, when I try to replace a variable which before was was an array with length 1 with one that is longer ("list assignment out of range" is thrown when trying to assign a value to the second array element)
I tried using locals()[variable] = [-1, -1, -1] as well as exec(variable + ' = [-1, -1, -1]') to set the variable beforehand.
My code for reference:
exec('tmp = ' + variable) # save variable in case input gets reset
exec(variable + " = [-1, -1, -1]") # replace with 3-length array
try:
# set the first array element according to user input
exec(variable + '[0] = float(input("Enter lower bound for " + variable + ": "))')
except ValueError: # in case user is dumb
print("Invalid input")
exec(variable + ' = tmp')
continue
try:
# set the second array element according to user input (this line throws the error)
exec(variable + '[1] = float(input("Enter upper bound for " + variable + ": "))')
if eval(variable + '[1] < ' + variable + '[0]'): # more user safeguards
print("Value can't be lower than " + str(aq_p[0]))
exec(variable + ' = tmp')
continue
except ValueError:
print("Invalid input")
exec(variable + ' = tmp')
continue
For some context: It's about setting up a physics simulation where a dozen parameters have to be set (and later versions may include other parameters) which is why I want to keep the code as general as possible instead of hard-coding the input for every parameter. I wanted to avoid using a dictionary with all the parameters in it, as that may complicate other things and was hoping to be able to use locals() similarly.
As a side note: The continues in the code are for a larger loop which is too long to include here.

Dictionary Item not populating correctly

I am out of wits on this one. I have a list like below that is available on the fly. I want to be able to create an array or a collection so that I could use it further in a loop.
Xob::SISBTXTRPR-5298
Xob::SISBTXTRPR-5326
Xob::SISBTXTRPR-5327
Xob::SISBTXTRPR-5328
Yob::SISBTXTRPR-3999
Yob::SISBTXTRPR-4000
I have tried to create a dictionary item like below but the output is not what I am expecting
While i <= iPuntedIssuesCount
If sRemovedStoriesForTaskTracker.Exists(Trim(JSONObj("contents")("puntedIssues")(i)("assigneeName"))) Then
sRemovedStoriesForTaskTracker(Trim(JSONObj("contents")("puntedIssues")(i)("assigneeName"))) = sRemovedStoriesForTaskTracker(Trim(JSONObj("contents")("puntedIssues")(i)("assigneeName"))) & " + " & JSONObj("contents")("puntedIssues")(i)("key")
Else
sRemovedStoriesForTaskTracker.Add key:=Trim(JSONObj("contents")("puntedIssues")(i)("assigneeName")), Item:=JSONObj("contents")("puntedIssues")(i)("key")
End If
i = i + 1
Wend
sRemovedStoriesForTaskTracker is the dictionary item.
The output in the dictionary items that I am getting is like so:
Xob::SISBTXTRPR-5298 + SISBTXTRPR-5326 + SISBTXTRPR-5327 + SISBTXTRPR-5328.
I want the dictionary to populate like this
Xob::SISBTXTRPR-5298
Xob::SISBTXTRPR-5326
Xob::SISBTXTRPR-5327
Xob::SISBTXTRPR-5328
You don't show your source JSON, or how you're outputting the dictionary values, and your posted code doesn't seem to match what you say you want to do.
In any case, your code as-posted would benefit hugely from the use of a few variables as noted by #Damian. It's so dense it's difficult to follow.
While i <= iPuntedIssuesCount
Set d = JSONObj("contents")("puntedIssues")(i)
k = Trim(d("assigneeName"))
v = d("key")
If dictRemoved.Exists(k) Then
dictRemoved(k) = dictRemoved(k) & " + " & v
Else
dictRemoved.Add k, v
End If
i = i + 1
Wend

SSRS - Line break in Matrix cell

In a SSRS Matrix cell I want to be able to have a line break between each output given.
I have the following code in my MS SQL Server Stored Procedure which I then point my SSRS report to
SELECT Customer, Hostname, (QName + QHostname + Qtag + QSerial + QCategory + QType + QItem + QManu + QModel + QVersion) AS AdditionalInfo1
FROM TableQ
At the moment in the AdditionalInfo1 cell when one of the options is returned they are separated by a comma
e.g.
QName, QHostname, Qtag.
Instead I would like them to be separated by a line break all within the same cell
e.g.
QName
QHostname
Qtag
I have tried putting + char(13) + between each Q... in AdditionalInfo1 but this didn't work.
For SSRS, you want to use Chr(10), not Chr(13). I've used this in expressions and as a Join delimiter argument and it produced the desired effect: line breaks within the textbox.
Edit:
Below is an expression that will include the fields with line breaks if a value is present, or omit both if the field is null.
=Fields!QName.Value
+ IIF(ISNOTHING(Fields!QHostname.Value),"", vbCrLf + Fields!QHostname.Value)
+ IIF(ISNOTHING(Fields!Qtag.Value),"", vbCrLf + Fields!Qtag.Value)
+ IIF(ISNOTHING(Fields!QSerial.Value),"", vbCrLf + Fields!QSerial.Value)
+ IIF(ISNOTHING(Fields!QCategory.Value),"", vbCrLf + Fields!QCategory.Value)
+ IIF(ISNOTHING(Fields!QType.Value),"", vbCrLf + Fields!QType.Value)
+ IIF(ISNOTHING(Fields!QItem.Value),"", vbCrLf + Fields!QItem.Value)
+ IIF(ISNOTHING(Fields!QManu.Value),"", vbCrLf + Fields!QManu.Value)
+ IIF(ISNOTHING(Fields!QModel.Value),"", vbCrLf + Fields!QModel.Value)
+ IIF(ISNOTHING(Fields!QVersion.Value),"", vbCrLf + Fields!QVersion.Value)
Instead of concatenating all the 'Q' columns into a single string keep them as separate fields. Then create individual placeholders in a single cell, one for each field. You can do this quite quickly by clicking into the cell (which is rich TextBox) and typing the field name (as it appears in the DataSet) enclosed by square brackets
eg:
[QName]
[QHostname]
[Qtag]

ACCESS 2007 - Form / subform filtering between dates

In ACCESS 2007 I have a main form with two unbound comboboxes named cmbStavOd and cmbStavK, both formatted as Short Date.
I have a subform named frm_qryNaklady_subform, based on a query with a field named datNakladDatum (textbox name datNakladDatum), formatted as Short Date.
I'd like to allow users to enter a date range and have the subform filtered to only show records of the date range entered in the main form boxes.
I'm using a VBA code in AfterUpdate event like:
Dim datRokMesiacOd As Date
Dim datRokMesiacDo As Date
Dim strFilterNaklady As String
datRokMesiacOd = DateSerial(Year(cmbStavOd), Month(cmbStavOd), 1) 'begin Date
datRokMesiacDo = DateSerial(Year(cmbStavK), Month(cmbStavK) + 1, 1) - 1 'end Date
strFilterNaklady = "[datNakladDatum] Between #" & datRokMesiacOd & "# And #" & datRokMesiacDo & "#"
With Me.frm_qryNaklady_subform.Form
.Filter = strFilterNaklady
.FilterOn = True
End With
For instance, result for strFilterNaklady looks like this: "[datNakladDatum] Between #1. 1. 2015# And #31. 12. 2015#".
By debugging the code I receive an error message at statement:
With Me.frm_qryNaklady_subform.Form
.Filter = strFilterNaklady
.FilterOn = True
End With
Error 3709 - The search key was not found in any record.
But the underlying query contains tons of records fitting entered date range.
I'm playing with date filtering syntax all the day, but without success.
Do you see where I'm going wrong?
You need proper date formatting:
strFilterNaklady = "[datNakladDatum] Between #" & Format(datRokMesiacOd, "yyyy\/mm\/dd") & "# And #" & Format(datRokMesiacDo, "yyyy\/mm\/dd") & "#"
Also, this can be reduced to:
datRokMesiacDo = DateSerial(Year(cmbStavK), Month(cmbStavK) + 1, 0) 'end Date

Sort combobox alphabetically

To begin, yes I've searched and saw the other articles regarding this and not they don't help.
I have a very simple code and I just need to sort the combo box after I populate it.
So far I have this:
'Doctor comboBox
For Each doc As Doctor In DoctorList
CBX_Doctors.Items.Add(doc.FirstName + " " + doc.LastName)
Next
I need to sort it by first name.
Use the OrderBy clause on your object. This predicate will order them by the field given.
For Each doc As Doctor In DoctorList.OrderBy(Function(o) o.FirstName)
CBX_Doctors.Items.Add(doc.FirstName + " " + doc.LastName)
Next
After you add your list, use CBX_Doctors.Sorted = True. Like this:
For Each doc As Doctor In DoctorList
CBX_Doctors.Items.Add(doc.FirstName + " " + doc.LastName)
Next
CBX_Doctors.Sorted = True