rails validation reject if form is all whitespace [duplicate] - ruby-on-rails

This question already has answers here:
How to validate text isn't blank in Rails
(3 answers)
Closed 6 years ago.
I'm trying to find a way to reject creation of a message if the form filled out is empty (including spaces and new lines). Currently I have the form set to required: true but that doesn't stop a user from hitting the spacebar and sending the message. I don't know if Rails has a built in validation or if there is some regex I would have to use.

You're after a presence validator in your model. It will explicitly require that your field's present? be true, which it won't be if the column contains only whitespace.

Related

How to put a hyperlink on some words only in a TextField on JasperStudio? [duplicate]

This question already has answers here:
<a> html tag used for hyperlink doesn't work in Jasper Report
(4 answers)
Closed 3 years ago.
I am currently creating a report with JasperStudio 6.9 and I need to put a hyperlink within a TextField. The report itself will then be sent as a stream through a server. Is there any way to do so in JasperStudio or any workaround?
Currently, I only managed to put the link over the whole TextField from the hyperlink properties in the item's tab but cannot put it only on the words I want. As far as I am aware of, it is not possible to do so, but I wanted to be certain.
I don't really have any code to show since it's all made through the software's UI.
Let's say the TextField has the sentence "Please contact us at this address", I would like the words "This address" to bear the hyperlink, not the entire sentence.
Thanks in advance!
You should write something like this in the "Text Field Expression":
"Contact us at this address."
or (if the email does not come from the data retrieved ):
"Contact us at this address."
and change the "Markup" property to "html".

How to fill in a datetime field with capybara?

I found this similar question How to fill in a datetime-local field with capybara?, and the only answer in this thread is not working. So I decided to open this question. It seems like there's no documentation or tutorial about this. Have any solution? It will be a great help!
The keys different browsers accept for setting a datetime input field are diffrent, however if you're using selenium with chrome and you are actually attempting to fill in a visible <input type="datetime-local"> element, as your question states, then the answer in the question your linked to should work - Here is a gist that shows it working - https://gist.github.com/twalpole/a541746b354afde8e82fa89a35a9b2da
The important part in that answer is the format of the string you send since it needs to match the keys the browser is expecting for setting that input (to_json doesn't match that format)
Therefore, in your case of wanting to set DateTime.current it should be something along the lines of
fill_in 'id/name/label of input', with: DateTime.current.strftime("%m%d%Y\t%I%M%P")
If that doesn't work for you then most likely you're not actually attempting to fill a visible <input type="datetime-local"> field (maybe you're using some kind of JS widget that replaces/hides the input???) and you'll need to specify the exact HTML you are trying to fill in your question.
from what I understand, you need to fill in a string representation of the datetime format
examples of such dates are
1990-12-31T23:59:60Z
or
1996-12-19T16:39:57-08:00
so something like
fill_in datetimeinput, with: "1990-12-31T23:59:60Z"
should work (hope so!)

Survey Monkey Api - Get label text for response choice_id [duplicate]

This question already has answers here:
How to get text response in survey monkey via API
(2 answers)
Closed 7 months ago.
I'm grabbing survey responses using "/surveys/" . $id . "/responses/bulk". For multiple choice questions, how do I include the label text for a response? Only choice_id is given. I've looked in the document and can't seem to find a clue.
Thanks!
Dylan
Use the following API endpoint pattern to fetch all the information on the question, including the selects:
https://api.surveymonkey.com/v3/surveys/{survey_id}/pages/{page_id}/questions/{question_id}

Check variable exists in current url in classic asp [duplicate]

This question already has answers here:
How to check if a POST submitted field exists in VBScript?
(4 answers)
Closed 5 years ago.
Is there a way to check if a variable exists on the current page in asp? i.e.
For the url: https://stackoverflow.com/?question=something
I'd like to check if the ?question variable exists.
<%Request.ServerVariables("Query_String")%> would give question=something but I just want to know if the current url contains ?question. I don't care what the actual value is as long as it exists.
Ask the Request collection:
HasParam = Request("question").Count > 0

Is there any way to keep validate field optional in rails?

I have User model which includes 7 fields. for all these fields validation is written.i have two form where i am displaying fields depend on condition. in one form i have name password and city and other form i have role,phone and name.
When i try to submit the first form i got the error which says phone and role field are required resulting into failure of form.
Is there any way by which i can submit both form without getting the validation errors ??
Note : i want my logic to be in model only.. Please help me with this problem.
You could use a conditional validation to achieve what you want:
See here: http://guides.rubyonrails.org/active_record_validations.html#conditional-validation
However, this can quickly get hard to manage. Depending on the condition you're switching on, it'd probably be a cleaner design to use a 'Form Object' which will give you more control and let you do validations without the messy conditional logic.
See section #3 of this blog post for more detail:
http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/
Using this pattern, you would check for your condition in the controller then determine which form object to send to the view.

Resources