ellie stone
ellie stone

Reputation: 125

How can I turn the focus off when a new input type is added?

How can I turn the focus off when a new inpu is added? I want to do this because when i am on my iPad and press "Add Field" it automatically brings up the keyboard. This is very annoying because sometimes I want to add a few new input fields before entering data.

		$('.multi-field-wrapper').each(function() {
			var $wrapper = $('.multi-fields', this);
			$(".add-field", $(this)).click(function(e) {
				$('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('input').val('').focus();
			});
			$('.multi-field .remove-field', $wrapper).click(function() {
				if ($('.multi-field', $wrapper).length > 1)
					$(this).parent('.multi-field').remove();
			});
		});
			
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="" method="POST" style="height:50px;">
 <input type="submit" name="stocksave" value="Save" class="float" style = "float:right;">  
 </br></br>
	 
   <div class="multi-field-wrapper focusoff">
   
	  <div class="multi-fields focusoff">
		 <div class="multi-field focusoff">
			<input type="text" name="stockitem[]" autocomplete="off" class="focusoff">
			<select name='piecesdd[]' style='width:150px; '>
			
			   <option value='0'>PIECES</option>
			   <?php
				  $count = 1;
				  while ($count<=100) {
					echo "<option value='".$count."'>".$count."</option>";
					$count++;
				  };
				  ?>
			</select>
			<button type="button" class="remove-field">Remove</button>
			
			<button type="button" class="add-field">Add field</button>
			
		 </div>
		  
	  </div>
     
	</div>
	
  
</form>

Upvotes: 3

Views: 100

Answers (1)

Guruprasad J Rao
Guruprasad J Rao

Reputation: 29683

Remove .focus() from below line on .add-field - click event

$('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper)
.find('input').val('').focus()

So it would be just

$('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper)
.find('input').val('')

Upvotes: 2

Related Questions