vue.js see if input matches regex - regex

I have a input field that I like to compare to several regex.
If the input is correct, the method should be executed.
I think I'm doing it completely wrong.
<p class="control">
<input ref="barcode" id="BarcodeInput" v-model="barcode" v-on:keyup.enter="processBarcode" class="input" type="text" placeholder="Barcode" autofocus />
</p>
<p class="control">
<button v-on:click="processBarcode" class="button is-primary" >Go!</button>
</p>
method:
if (document.getElementById("BarcodeInput").value == "31334866-001"){
Now i can put the barcode in the textbox and i can use the methode.
If i try:
if (document.getElementById("BarcodeInput").value == "^\d{8}-\d{3}$"){
the Barcode: 31334866-001 doesnt work.

So you'll want to first use a v-model for the barcode input linked to your data. This will save you the trouble of getting the element. Then do your validation in the processBarcode function.
If you want to clear the box, just clear the v-model variable stored in data (with two-way binding, changing one changes the other).

Related

How to locate a hidden element on a webpage

I am trying to pass some content in the textbox using the following:
driver.find_element_by_xpath('path').send_keys(value)
Apparently nothing is getting passes.
Similar issue with clicking button:
driver.find_element_by_xpath('path').click()
This is also not working, in the code i could see
display:none:
<li style="display:none">
</li>
</ul></div>
<div class="row form-group">
<div class="col-sm-12 form-group">
<label for="Username">Username</label>
<input autocomplete="off" class="form-control" data-val="true" data-val-
required="User name is Required" id="Username" name="Username" type="text" value="">
As per the HTML you have shared and #Sighil pointed out the style attribute display: none is part of the previous <li> tag which must not affect the Username field. To pass some text to the Username field you can use the following line of code :
driver.find_element_by_xpath("//input[#class='form-control' and #id='Username']").send_keys("Dimple Mathew")
It may be possible you have to induce a waiter for the Username field to be interactable and in that case you have to induce WebDriverWait as follows :
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#class='form-control' and #id='Username']"))).send_keys("Dimple Mathew")
Use explicit wait statement before you use sendkeys or click. As per my understanding element is not visible while click or sendkeys.
For your reference visit Explicit and Implicit Wait Docs
I was having a similar issue not to long ago, try this:
js= "document.getElementById('Username').value = '" + str(YOURVALUE) + "';"
driver.execute_script(js)
It worked for me, hope this helps.

Django simple URL Mapping issue

Have a small issue and wondering if some one can help me out.
I have a text search box like this that
<form class="navbar-form navbar-left" role="search" action="/library/search/">
<div class="form-group" style="display:inline;">
<div class="input-group">
<input class="form-control" id="q" name="P" type="text" placeholder="Book Search"">
<span class="input-group-btn">
<button class="btn btn-primary" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</span>
</div>
</div>
</form>
When I type in a word and hit submit a URL is generated as follows,
http://127.0.0.1:8000/library/search/?P=Harry+Potter
In the URLs.py I have something like this
url(r'^search/(?P<search_result>[\w|\W.#+-]+)/$', views.search_view, name='search_view')
However the above url is not being matched by the regex statement. If I manually remove the ?P= from the url it works fine.
I have tried some of the following combination and they didn't work either
url(r'^search/(?P(.*)<search_result>[\w|\W.#+-]+)/$', views.search_view, name='search_view')
Any idea what it could be ?
Thanks
You've misunderstood what ?P means in a regex. It states that the group is a named group, which is captured and sent to a view by a keyword argument. The URL that would satisfy that regex is like this:
/library/search/harrypotter/
But that's not at all what you want from a search; you want something like the one you have created, ie library/search/?P=harry+potter. For that you just want a URL without parameters:
r'^search/$'
and get the data in the view:
query = request.GET['p']
although you probably want to use q rather than p.

Chrome Vox Shift Alt Left arrow reads all following elements on page

Chrome Vox Shift Alt Left arrow reads all following elements on page on following structure. Now keeps focus on first input, I am trying to move from Input to label, and focus goes on asterisk span and label both. And it reads next input (email input box)and span also. Is there any fix for this?
<span>* </span>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<br/>
<span>* </span>
<label for="email">Name:</label>
<input type="text" name="email" id="email">
Your description is very confusing to answer. But this is how I understood it... You don't want the chromevox screen reader to announce the asterisk.
So what you can do is add this to the span.
<span aria-hidden="true">* </span>
Now I'm assuming you are using an asterisk to signify something is required... so you should add this to the input
<input type="text" name="email" id="email" required>
You need to add required to the input.
Now you can also control the flow of how the screen reader reads elements using tab index. But typically people don't use tab-index of a positive integer so it would need to be tab-index="0"
Hope This helps!

HTML Pattern - regex not working

I'm trying the pattern attribute for the first time, and I can't get it to work (my browser does support it, though).
Right now I have:
input type="text" pattern="[a-zA-Z0-9]{6}" name="formName"
The first problem is that is doesn't notify me if it's blank; the second problem is that if I do type in something, it won't accept it. I want it to accept alphanumeric characters and be exactly 6 characters is length. I tried it with forward slashes and a few other variations.
As Duikboot already pointed out, the right way to do it is:
<input type="text" name="formField" pattern="[a-zA-Z0-9]{6}" required>
The required attribute causes the validation to fail, when the field is empty.
The pattern attribute defines the regex to test against, when the field is not empty.
(Your initial pattern seems to work fine.)
More info can be found here.
This is simple enough so as not to require a demo, but nonetheless you can find one here.
Works for me here : http://jsfiddle.net/barbuslex/nR6yg/
<form>
<input type="text" pattern="[a-zA-Z0-9]{6}" name="formName" />
<input type="submit" value="OK" />
</form>
I use Google Chrome
You simply need to add the required attribute to your tag, which will notify the user if they attempt to send the form with that very field blank.
<input type="text" pattern="[a-zA-z0-9]{6}" name="formName" required>
Try this code its working perfectly
<html>
<body>
<form action="demo_form.asp">
Country code: <input type="text" name="country_code" pattern="[A-Za-z]{3}" title="Three letter country code">
<input type="submit">
</form>
</body>
</html>
Enter invalid country code and click submit button. Then You can get a message (title="Three letter country code")

Django template input button post problem

I try to post value of input buttons in Django but I couldn't
This is my template
<form id="ReviewRateForm" method="post" action="/review/post/rate/">
<input type="button" hint="V1" title="V" value="1" id="radio{{ forloop.counter }}-1" type="button" name="qid[{{forloop.counter}}]"></input>
<input type="button" hint="V1" title="V" value="2" id="radio{{ forloop.counter }}-1" type="button" name="qid[{{forloop.counter}}]"></input>
<input type="button" hint="V1" title="V" value="1" id="radio{{ forloop.counter }}-1" type="button" name="qid[{{forloop.counter}}]"></input>
</form>
However, when I debug it I couldn't reach the values of that input buttons in my view.
What is the problem or how can I overcome it?
The values can be accessed by the name of the input from request.POST. However, you're dynamically naming the inputs, which is going to make things more complicated when you go to retrieve those values.
Example without taking into consideration the dynamic naming:
quid1 = request.POST.get('quid1')
The problem might be with your browser rather than with django.
If you use the button element in an HTML form, different browsers will submit different values. Internet Explorer will submit the text between the <button> and </button> tags, while other browsers will submit the content of the value attribute.
Update: Oh, you are not using <button> elements, I read too fast. Sorry. Then this answer is not relevant.