JSFiddle - React, Tailwind, and code Playground
JavaScript
var $input = $('<div/>').html( $('<input/>').addClass('value') );
$('form').append( $input.clone() );
$(window).on( 'focus', 'form input', function(e) {
// Add new input if the focused one is empty
if(!this.value && $(e.target).parent().is(':last-child')) {
$('form').append( $input.clone() );
}
});
$(window).on( 'blur', 'form input', function(e) {
var $this = $(this);
if(!this.value) {
console.log('REMOVING INPUT');
$this.parent().remove();
} else {
$this.attr('name', 'item-'+$this.val());
}
});