C5-8.0+ input class not active if input added by jQ in Add Block form
Permalink
When editing a block, the Add Block form inserts input fields with data from the DB. New empty input text fields can also be added with a button on the same form.
The auto and manual insert codes are identical:
Both auto and manually inserted inputs have 'decimals' class - verified in the console. The $('.decimals').keydown only allows numeric key presses, no letters.
But the problem is the 'decimals' class is only active, that is the keydown only works on the auto inserted inputs and it does NOT work on the manually inserted inputs, despite the latter having it.
Why is the 'decimals' class not recognised or the keypress not working on the manually added inputs?
Thank you.
The auto and manual insert codes are identical:
<script type="text/javascript"> $(function(){ // Auto insert inputs with values from DB var price = $('<td><?php echo $form->text('prices[]', $row['price'], ['class' => "decimals"]); ?></td>'); // Manually insert inputs with the button $("#add").click(function() { var price = $('<td><?php echo $form->text('prices[]', '', ['class' => "decimals"]); ?></td>'); }); // Check if only numeric keys pressed $('.decimals').keydown(function (e) { ... });
Both auto and manually inserted inputs have 'decimals' class - verified in the console. The $('.decimals').keydown only allows numeric key presses, no letters.
But the problem is the 'decimals' class is only active, that is the keydown only works on the auto inserted inputs and it does NOT work on the manually inserted inputs, despite the latter having it.
Why is the 'decimals' class not recognised or the keypress not working on the manually added inputs?
Thank you.
to
where
ref.http://api.jquery.com/on/ for more info on Delegated events